Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>class MyClass &lt; BasicObject class Error &lt; ::NoMethodError def method_missing(....) raise Error end end end p MyClass.superclass # =&gt; BasicObject p method(:raise).owner # =&gt; Kernel </code></pre> <p>Now <code>Kernel</code> is not present in the ancestor chain of <code>MyClass</code> class. Thus when you are calling <code>raise</code> inside the <code>method_missing</code> method,which in turn again call <code>method_missing</code> method(Because <code>raise</code> is not a method of class <code>MyClass</code>,nor the owner <code>Kernel</code> mixed in <code>Myclass</code>,so <code>raise</code> method look up is failed,and causing repeatedly call to <code>method_missing</code>. Thus it results in error as <code>SystemStackError: stack level too deep</code>. I tried here to recreate the scenarios what you are facing as below :</p> <pre><code>class Foo &lt; BasicObject def method_missing(name,*args) p "hi" end end Foo.new.baz # stack level too deep (SystemStackError) </code></pre> <p>Here also the reason is same.There is no <code>Foo#baz</code> method,so <code>method_missing</code> called first time. Now inside <code>method_missing</code>, I am trying to call another method,which is method of class <code>Kernel</code>. Now <code>Kernel</code> is not mixed in neither <code>BasicObject</code>,nor in <code>Foo</code>. So method look up got failed,and <code>method_missing</code> called repeatedly due to call to the method <code>Kernel#p</code>,and it causes the error. To fix this I would do as below :</p> <pre><code>class Foo &lt; BasicObject include ::Kernel def method_missing(name,*args) p "hi" end end Foo.new.baz # =&gt; "hi" </code></pre> <p>Hope you got the point now.</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