LoginSignup
25
21

More than 5 years have passed since last update.

rubyでメソッドがどこで定義されているか調べる方法

Posted at

メソッドの定義元クラス

helper.method(:link_to)
#=> <Method: ActionView::Base(ActionView::Helpers::UrlHelper)#link_to>

どのファイル?

helper.method(:link_to).source_location
#=> ["/Users/hoge/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/actionpack-4.0.2/lib/action_view/helpers/url_helper.rb", 174]

行数も出る。

define_methodとかメタプログラミングしていても追いかけてくれるので便利です。

25
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
21