Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, it has been replaced by a clever use of method overriding in modules and the <code>super</code> keyword.</p> <p>Basically, you define the original function in an included module, and override it in another included module. When you call <code>super</code> in the overriding function, it calls the original function. But there is one catch. You have to include the extending modules <strong>after</strong> including the base module, and in the order you want the chaining to occur.</p> <pre><code>class Something module Base def my_method # (A) original functionality end end module PreExtension def my_method # (B) before the original super # calls whatever was my_method before this definition was made end end module PostExtension def my_method super # calls whatever was my_method before this definition was made # (C) after the original end end include Base # this is needed to place the base methods in the inheritance stack include PreExtension # this will override the original my_method include PostExtension # this will override my_method defined in PreExtension end s = Something.new s.my_method #=&gt; this is a twice extended method call that will execute code in this order: #=&gt; (B) before the original #=&gt; (A) the original #=&gt; (C) after the original </code></pre> <p>Ryan Bates of <a href="http://railscasts.com" rel="nofollow noreferrer">Railscasts</a> talks about <a href="http://railscasts.com/episodes/232-routing-walkthrough-part-2" rel="nofollow noreferrer">how this is used in the Rails Routing code</a>. I'd recommend watching it, and his other screencasts. They have the power to transform a knitting grandmother into a Rails guru.</p> <p><em>PS: Credit goes to <a href="https://stackoverflow.com/users/4937/peeja">Peeja</a> for correcting a fundamental error in my original answer. Thanks.</em></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. 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