[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Method origin?

John Wells

9/28/2007 12:20:00 AM

Guys,

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

Thanks,
John

4 Answers

Stefan Rusterholz

9/28/2007 1:01:00 AM

0

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

Phlip

9/28/2007 1:11:00 AM

0

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


Phrogz

9/28/2007 1:21:00 AM

0

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?

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

http://rcrchive.n...

Disclaimer: I proposed that particular RCR. :)

Paul Brannan

9/28/2007 2:50:00 PM

0

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?

Nodewrap can do it:

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

Paul