Method origin?

Guys,

In a deep inheritance tree, is there an easy way to determine the origin or source (module, class) of a method?

Thanks,
John

John Wells wrote:

Guys,

In a deep inheritance tree, is there an easy way to determine the origin
or source (module, class) of a method?

Thanks,
John

a) Use fri (fast-ri)
b) Use Method#inspect, example: .method(:find) # => #<Method:
Array(Enumerable)#find>

Regards
Stefan

···

--
Posted via http://www.ruby-forum.com/\.

If you'd like something better than this, then vote for the
Method#owning_class (or better name) aspect of RCR 15.

http://rcrchive.net/rcrs/15

Disclaimer: I proposed that particular RCR. :slight_smile:

···

On Sep 27, 6:20 pm, John Wells <li...@sourceillustrated.com> wrote:

In a deep inheritance tree, is there an easy way to determine the origin or source (module, class) of a method?

Nodewrap can do it:

irb(main):001:0> require 'nodewrap'
=> false
irb(main):002:0> Hash.instance_method(:map).origin_class
=> Enumerable

Paul

···

On Fri, Sep 28, 2007 at 09:20:01AM +0900, John Wells wrote:

Guys,

In a deep inheritance tree, is there an easy way to determine the
origin or source (module, class) of a method?

Stefan Rusterholz wrote:

John Wells wrote:

In a deep inheritance tree,

Note: Deep inheritance trees might be a design issue.

is there an easy way to determine the origin
or source (module, class) of a method?

a) Use fri (fast-ri)
b) Use Method#inspect, example: .method(:find) # => #<Method:
Array(Enumerable)#find>

b) seems to assume an irb environment that calls .inspect automatically. Try:

  puts .method(:find).inspect

New question: Parsing the (Enumerable) out would be tacky, so how do we do what .inspect was doing when it built that string for us?

···

--
  Phlip