Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just to extend the answer given by bor1s, about the <em>private</em> methods:</p> <p>In ruby you have "private" and "protected" methods. What bor1s says, is correct when talking about "protected" methods. Declaring a method "private" additionally prevents <em>other instances of the same class</em> from using the method.</p> <p>When you call a "private" method, you cannot use a dot in front of it - you cannot even use <code>self.</code>, even though using or omitting <code>self</code> has usually the same effect.</p> <pre><code>class Xyzzy private def foo puts "Foo called" end public def do_it foo # &lt;= Is OK self.foo # &lt;= raises NoMethodError end end Xyzzy.new.do_it </code></pre> <p>If you change 'private' to 'protected' in the code above, no error will be raised.</p> <p><strong>And about modules:</strong></p> <p>The final result of defining a method in <code>Kernel</code> and extending <code>Kernel</code> with the method defined in some module is the same: in both cases the method is global.</p> <p>Using a module is just a little more elegant, as it groups <em>your</em> changes in one place, but I would say it's a matter of personal taste.</p> <p>Usually you do not include methods in Kernel or Object (as it may be a little dangerous), but you include (or extend) a specific class or object which needs these methods, and in this case you <em>need</em> your methods grouped in a module.</p> <p>Even Rake in version 0.9.0 stopped including the DSL commands in Object:</p> <blockquote> <p>== Version 0.9.0</p> <ul> <li><em>Incompatible</em> *change*: Rake DSL commands ('task', 'file', etc.) are no longer private methods in Object. If you need to call 'task :xzy' inside your class, include Rake::DSL into the class. The DSL is still available at the top level scope (via the top level object which extends Rake::DSL).</li> </ul> </blockquote>
 

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