Reflecting on an Association Extension

Hi all.

How can I reflect on a method which had been extended into an association.

If i try model.association.method(:method_name) I get an undefined error yet I can invoke it via model.association.method_name. I've tried several different approaches to get at the method but can't seem to be able to get hold of it.

Thanks Garrett

class Post    has_many :comments do      def some_method      end    end end

The basic issues is that post.comments is not an array, it's an instance of a proxy class that will (when needed) load the collection and forward methods. so when you call post.comments.method(:some_method) that's being forwarded on to the array itself.

You can use post.comments.proxy_respond_to?(:foo) to find if the proxy itself response to a method, but the 'method' method has been undef'd on association proxies.

Fred.

Thanks Fred

Is there no way then for me to check that two method names actually have the same implementation.

I had been intending the test that

class Post    has_many :comments do      def foo      end      alias_method :bar, :foo    end end

post.comments.method(:foo) == post.comments.method(:bar)