Does Ruby have a 'which' like method

0 views
Skip to first unread message

Scott G Smith

unread,
Oct 6, 2009, 9:38:27 PM10/6/09
to forumgrouper
Most UNIX shells have a which command.

It tells me the file which corresponds to a shell command.

Demo:
which date
/bin/date

In ruby,
Suppose I'm dealing with a String.

This String has had some methods mixed-in.

For example,

s = 'hello'
p(s.length)

Is there a way I can find the module or string.rb which defined the
length() method?

I'd like it to work like this:

p(s.which('length'))
/my/rubyfiles/string_module.rb

Thanks,
Scott

Reply all
Reply to author
Forward
0 new messages