Josh S. wrote:
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
has_many :comments do
alias_method :bar, :foo
post.comments.method(:foo) == post.comments.method(:bar)
The #method() method in Ruby isn’t very helpful for comparing
“foo”.method(:length) == “foo”.method(:length)
If you need to check to see if an extension has been included in an
association, you could grope through the ancestor modules. Or it may be
easier to define a duck-type predicate in the extension module, like
#is_my_fancy_type?, that you can use to check if the association has
Ah, oops. Ruby’s per-object methods get me again. Method identity is
unique per instance. The two “foo” strings in my other example are of
course different objects. Sigh. Symbols are the same instance though,
:foo.method(:to_s) == :foo.method(:to_s)
So if you have the exact same association instance, you could actually
compare implementations of messages to see if they were the same method.
I still don’t get the use case though.