Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Good question, but you are making it too complicated. Keep in mind a few principles and it should all be clear...</p> <ul> <li><p>The types will be resolved dynamically, so if a <code>show</code> exists <em>anywhere</em> in the object's class hierarchy <em>at the moment it is actually called</em> then Ruby will find it and call it. You are welcome to type in method calls to anything that may or may not exist in the future and it's legal ruby syntax and it will parse. You can type in an expression that includes a reference to <code>this_will_never_be_implemented</code> and no one will care unless it actually gets called.</p></li> <li><p>Even in Java, there is only one actual object. Yes, you may have a method in the superclass that's calling a method, but it <em>is</em> an instance of the derived class (as well as an instance of the base class) and so you can count on the new <code>show</code> being called.</p></li> <li><p>In a sense, every Ruby class is an abstract class containing stubs for every possible method that might be defined in the future. You can call anything without access qualifiers in the base class or derived class.</p></li> </ul> <p>If you want a null superclass implementation, you may want to define one that does nothing or raises an exception.</p> <p><em>Update:</em> Possibly, I should have just said "call <code>show</code> like any other method" and left it at that, but having come this far I want to add: You can also implement <code>show</code> with Ruby's version of multiple inheritance: <strong>include</strong> <em>SomeModule</em>. Since you are obviously interested in Ruby's object model, you might implement your attribute with a mixin just for fun.</p>
 

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