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>
Written by Juris Galang
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#