How to see, where method is defined, in runtime
Sometimes you want to see, where some method is defined, right from console. For, example, there are two methods touch defined in Rails, ActiveRecord::Callbacks#touch and
ActiveRecord::Persistence#touch. Which implementation works for users? Simple solution is:
> User.first.method(:touch).owner
=> ActiveRecord::Callbacks
You can even see location of source file:
> User.first.method(:touch).source_location
=> ["/home/jaturken/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.13/lib/active_record/callbacks.rb", 257]
Written by Alex Teut
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#