A private method is internal to the implementation of a class, and it
can only be called by other instance methods of the class (or its
subclasses). Private methods are implicitly invoked on self, and may
not be explicitly invoked on an object. If m is a private method, then
you must ibnvoke it in functional style as m.
But look at this:
1.9.3p0 :032 > class Object
1.9.3p0 :033?> def apple2
1.9.3p0 :034?> puts 'apple2'
1.9.3p0 :035?> end
1.9.3p0 :036?> end
1.9.3p0 :037 > self.apple2
1.9.3p0 :038 > def apple2
1.9.3p0 :039?> puts 'apple2'
1.9.3p0 :040?> end
1.9.3p0 :041 > self.apple2
I invoked apple2 on self (an explicit receiver). However, according to
documentation, defining apple2 in Object should have made it private.
Only this would work:
1.9.3p0 :025 > class Object
1.9.3p0 :026?> private
1.9.3p0 :027?> def apple1
1.9.3p0 :028?> puts 'apple1'
1.9.3p0 :029?> end
1.9.3p0 :030?> end
1.9.3p0 :031 > self.apple1
NoMethodError: private method `apple1' called for main:Object
However, in the above example, I was forced to use the private method.
The documentation says "any global methods declared outside of a class
definition - those methods are defined as private instance methods of
In my first examples, I defined a method outside of class definition.
But was still able to invoke it on self (self being Object in that