Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can get a hint by inspecting the method:</p> <pre><code>Decorator.instance_method(:class) # =&gt; #&lt;UnboundMethod: Decorator(#&lt;Module:0x00000102137498&gt;)#class&gt; </code></pre> <p>The method's owner is <code>Decorator</code> but actually defined in <code>#&lt;Module:0x00000102137498&gt;</code>. So there is an anonymous module that defines it. Interesting... let's look at:</p> <pre><code>Decorator.ancestors # =&gt; [Decorator, Delegator, #&lt;Module:0x00000102137498&gt;, BasicObject] </code></pre> <p>There's that module again, between <code>Delegator</code> and <code>BasicObject</code>. So <code>Delegator</code> doesn't directly derive from <code>BasicObject</code>. If you look at the source code in <code>lib/delegate.rb</code> you find:</p> <pre><code>class Delegator &lt; BasicObject kernel = ::Kernel.dup kernel.class_eval do [:to_s,:inspect,:=~,:!~,:===,:&lt;=&gt;,:eql?,:hash].each do |m| undef_method m end end include kernel # ... </code></pre> <p>So a copy of the <code>Kernel</code> module is made, which doesn't have <code>to_s</code>, <code>inspect</code>, etc... but still has <code>class</code> and <code>instance_of?</code>. It's included in <code>Delegator</code> and that's where they come from.</p> <p>Note that <code>Object</code> inherits the same methods by including the <code>Kernel</code> module (but it includes the full module, of course):</p> <pre><code>42.method(:class) # =&gt; #&lt;Method: Fixnum(Kernel)#class&gt; </code></pre> <p>This is stated in the <a href="http://www.ruby-doc.org/core-1.9.3/Object.html" rel="nofollow"><code>Object</code> doc</a>:</p> <blockquote> <p>Object mixes in the Kernel module, making the built-in kernel functions globally accessible. Although the instance methods of Object are defined by the Kernel module, we have chosen to document them here for clarity.</p> </blockquote>
    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