When you send a message to an object, Ruby follows some path along
singleton object, class, included modules, superclasses, and so on.
Is there a way to know where the responding method is defined?
For example:
obj = MyClass.new
...
obj.f
The method f could be defined in MyClass or it could be just obj's
singleton method or whatever.
Is there a way to be sure of it?
I think I can find which class or module newly define a method.
But I don't know whether a method is redefined by a class or module.
Thanks.
Sam
Hi Sam,
You might look into Facets' nesting method. I don't recall exactly but
I think that might do the trick. Any way it shoul dgive you some leads
ast the very least.
http:://facets.rubyforge.org
T.
You can use #method for this:
irb(main):001:0> class Foo; def foo()end; def bar() end end
=> nil
irb(main):002:0> class Bar < Foo;def bar() end end
=> nil
irb(main):003:0> Bar.new.method :foo
=> #<Method: Bar(Foo)#foo>
irb(main):004:0> Bar.new.method :bar
=> #<Method: Bar#bar>
singleton method:
irb(main):005:0> obj = Bar.new
=> #<Bar:0x3c49d0>
irb(main):006:0> def obj.foo() end
=> nil
irb(main):007:0> obj.method :foo
=> #<Method: #<Bar:0x3c49d0>.foo>
Kind regards
robert
Oh, now I see.
Thank you, Robert.
Sam
I'll check it out.
Thank you.
Sam