Last Updated: February 25, 2016
·
475
· jurisgalang

Locate a method's implementation

With Ruby 1.9.x the Method class now comes with #source_location -which comes in handy when you're spelunking:

@acct.method(:host_mapping).source_location

- will return the actual path to the filename and line number where the method is defined:

["/path/to/some_file.rb", 42]

It wont work for natively compiled code, but you should still be able to just get an instance of the Method class and inspect it:

@acct.method(:host_mapping).inspect

- to get the name of the Class or Module location where #host_mapping is defined:

#<Method: Account(Account::Url)#url>