Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is really late, but here's how you can find where a method is defined:</p> <p><a href="http://gist.github.com/76951" rel="nofollow noreferrer">http://gist.github.com/76951</a></p> <pre><code># How to find out where a method comes from. # Learned this from Dave Thomas while teaching Advanced Ruby Studio # Makes the case for separating method definitions into # modules, especially when enhancing built-in classes. module Perpetrator def crime end end class Fixnum include Perpetrator end p 2.method(:crime) # The "2" here is an instance of Fixnum. #&lt;Method: Fixnum(Perpetrator)#crime&gt; </code></pre> <p>If you're on Ruby 1.9+, you can use <a href="http://www.ruby-doc.org/core-1.9.3/Method.html#method-i-source_location" rel="nofollow noreferrer"><code>source_location</code></a></p> <pre><code>require 'csv' p CSV.new('string').method(:flock) # =&gt; #&lt;Method: CSV#flock&gt; CSV.new('string').method(:flock).source_location # =&gt; ["/path/to/ruby/1.9.2-p290/lib/ruby/1.9.1/forwardable.rb", 180] </code></pre> <p>Note that this won't work on everything, like native compiled code. The <a href="http://www.ruby-doc.org/core-1.9.3/Method.html" rel="nofollow noreferrer">Method class</a> has some neat functions, too, like <a href="http://www.ruby-doc.org/core-1.9.3/Method.html#method-i-owner" rel="nofollow noreferrer">Method#owner</a> which returns the file where the method is defined.</p> <p>EDIT: Also see the <code>__file__</code> and <code>__line__</code> and notes for REE in the other answer, they're handy too. -- wg</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload