how to determine which file a method is defined in

F

Fenton Travers

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!
 
T

Tim Pease

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
 

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
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top