Forum: Ruby how to determine which file a method is defined in

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9593dc79efe1bb4bd8d3f7174b385c86?d=identicon&s=25 Fenton Travers (ftravers)
on 2007-08-01 22:57
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!
4d5b5dd4e263d780a5dfe7ac8b8ac98c?d=identicon&s=25 Tim Pease (Guest)
on 2007-08-02 00:26
(Received via mailing list)
On 8/1/07, Fenton Travers <fenton.travers@gmail.com> 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
454bd31c811ab511d9c993ec2b3e7d82?d=identicon&s=25 George Malamidis (Guest)
on 2007-08-02 00:41
(Received via mailing list)
Hi,

You might also want to try http://unroller.rubyforge.org/

George
This topic is locked and can not be replied to.