# How to determine which file a method is defined in

**URL:** <https://www.ruby-forum.com/t/how-to-determine-which-file-a-method-is-defined-in/111012>\
**Category:** Ruby\
**Created:** [August 1, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/how-to-determine-which-file-a-method-is-defined-in/111012 "2007-08-01T22:57:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ftravers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@ftravers](https://www.ruby-forum.com/u/ftravers)\
**Post date:** [August 1, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/how-to-determine-which-file-a-method-is-defined-in/111012/1 "2007-08-01T22:57:08Z")

</div>

I would like to know if there is a way to definitively tell which file a  
given method was defined in.

Basically I’m trying to understand what a method does and would like to  
look in the file that defines it to better understand it. I’ve got IRB  
running and I’d like to do something like:

self.method(“find”).inspect

but this doesn’t exactly tell me where the method is defined so I can’t  
go figure exactly what it does.

thx!

---

<div class="post-metadata">

**Author:** ![ftravers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@ftravers](https://www.ruby-forum.com/u/ftravers)\
**Post date:** [August 2, 2007, 12:26am UTC](https://www.ruby-forum.com/t/how-to-determine-which-file-a-method-is-defined-in/111012/2 "2007-08-02T00:26:35Z")

</div>

On 8/1/07, Fenton T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I would like to know if there is a way to definitively tell which file a  
> given method was defined in.

The simplest solution would be to use grep on the .rb files that you  
are requiring into your irb session. From a command prompt …

grep ‘def find’ `find . -name '*.rb'`

If that does not work for you, then you can set the SCRIPT\_LINES\_\_  
constant to capture the source code read in by the ruby interpreter  
when require is called. There is an example in the second version of  
the pickaxe book (page 528).

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![ftravers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@ftravers](https://www.ruby-forum.com/u/ftravers)\
**Post date:** [August 2, 2007, 12:41am UTC](https://www.ruby-forum.com/t/how-to-determine-which-file-a-method-is-defined-in/111012/3 "2007-08-02T00:41:36Z")

</div>

Hi,

You might also want to try [http://unroller.rubyforge.org/](http://unroller.rubyforge.org/)

George
