How to Find Where Ruby Methods are Defined
While my teammate Ben Orenstein was debugging an exception raised in a view, it became clear that a page_title
method had been defined twice. Grepping the project revealed only one definition. The second must be coming from a gem, but which one?
Ruby's Method#source_location
can answer the question:
method(:page_title).source_location
It revealed the culprit:
["/Users/ben/.rvm/gems/ruby-2.0.0-p353/gems/flutie-1.3.3/app/helpers/page_title_helper.rb", 2]
Written by Dan Croak
Related protips
11 Responses
Add your response
Add your response
I recommend trying out pry, it has edit
, ?
and $
commands for this and more. Of course, this one is still useful to know where pry is not available :)
over 1 year ago
·
I'd also like to mention that IntelliJ/RubyMine does this too with a simple shortcut. :)
over 1 year ago
·
As @hunterboerner said, I would like to share that we can easily locate a method by pressing the Command button (OSX) and simultaneously clicking the left mouse on the method in RubyMine.
over 1 year ago
·
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#