# Method origin?

**URL:** <https://www.ruby-forum.com/t/method-origin/115737>\
**Category:** Ruby\
**Created:** [September 28, 2007, 2:20am UTC](https://www.ruby-forum.com/t/method-origin/115737 "2007-09-28T02:20:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [September 28, 2007, 2:20am UTC](https://www.ruby-forum.com/t/method-origin/115737/1 "2007-09-28T02:20:19Z")

</div>

Guys,

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

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [September 28, 2007, 3:00am UTC](https://www.ruby-forum.com/t/method-origin/115737/2 "2007-09-28T03:00:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [September 28, 2007, 3:11am UTC](https://www.ruby-forum.com/t/method-origin/115737/3 "2007-09-28T03:11:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [September 28, 2007, 3:25am UTC](https://www.ruby-forum.com/t/method-origin/115737/4 "2007-09-28T03:25:59Z")

</div>

On Sep 27, 6:20 pm, John W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://rcrchive.net/rcrs/15)

Disclaimer: I proposed that particular RCR. 🙂

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [September 28, 2007, 4:50pm UTC](https://www.ruby-forum.com/t/method-origin/115737/5 "2007-09-28T16:50:15Z")

</div>

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
