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 W. 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

Stefan R. wrote:

John W. 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?

On Sep 27, 6:20 pm, John W. [email protected] wrote:

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

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 Fri, Sep 28, 2007 at 09:20:01AM +0900, John W. wrote:

Guys,

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs