Array.=== Bug, Rails Bug, or brain failure?

I think someone needs to take a look at Forwardable and Delegator.
Using a regular expression there just feels very, very wrong, too.

Regards,

Dan

···

-----Original Message-----
From: Jamis Buck [mailto:jamis@37signals.com]
Sent: Monday, May 23, 2005 2:46 PM
To: ruby-talk ML
Subject: Re: Array.=== Bug, Rails Bug, or brain failure?

Indeed, truth is stranger than fiction. :wink: Consider this
snippet from
AR's association_proxy.rb. (Here's where we're getting into some
pretty black magic):

    alias_method :proxy_respond_to?, :respond_to?
    instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil
\?|^proxy_respond_to\?|^send)/ }

    def method_missing(symbol, *args, &block)
      load_target
      @target.send(symbol, *args, &block)
    end

    def respond_to?(symbol, include_priv = false)
      proxy_respond_to?(symbol, include_priv) || (load_target &&
@target.respond_to?(symbol, include_priv))
    end

It's proxying to an array, and undefining all the relevant
methods on
the proxy so that things like #class get passed to the proxy, too.
Unfortunately, it looks like === doesn't get proxied, and I'm not
sure why. Perhaps Ruby does some optimizing under the covers?

At any rate, yah. It can be annoying. But you really are
dealing with
a proxy, and not an array. At least, not directly.

- Jamis