Method origin?

J

John Wells

Guys,

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

Thanks,
John
 
S

Stefan Rusterholz

John said:
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
 
P

Phlip

Stefan said:
John Wells wrote:

Note: Deep inheritance trees might be a design issue.
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?
 
P

Phrogz

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. :)
 
P

Paul Brannan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,178
Latest member
SusanaHam4

Latest Threads

Top