Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you redefine a method, you redefine a method; period.</p> <p>What you're doing when you include the second module with the <code>method_missing</code> method define is overriding the previously defined <code>method_missing</code>. You can keep it around by aliasing it before you redefine it, but you might want to watch out with that.</p> <p>Also, I don't know why you're calling <code>super.method_missing</code>. Once your <code>method_missing</code> definition is out of tricks you should let Ruby know it can continue on up the chain looking for a way to handle the call, all just by calling <code>super</code> (no need to pass arguments or specify a method name).</p> <p><strong>About Super</strong> (update)</p> <p>When you call <code>super</code> Ruby continues on up the inheritance chain looking for the next definition of the method invoked, and if it finds one it calls it and returns the response. When you call <code>super.method_missing</code> you call the <code>method_missing</code> method on the response to <code>super()</code>.</p> <p>Take this (somewhat silly) example:</p> <pre><code>class Sauce def flavor "Teriyaki" end end # yes, noodles inherit from sauce: # warmth, texture, flavor, and more! ;) class Noodle &lt; Sauce def flavor sauce_flavor = super "Noodles with #{sauce_flavor} sauce" end end dinner = Noodle.new puts dinner.flavor #=&gt; "Noodles with Teriyaki sauce" </code></pre> <p>You can see that super is a method just like any other, it just does some magic behind the scenes. If you call <code>super.class</code> here you're going to see <code>String</code>, since "Teriyaki" is a string. </p> <p>Make sense 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