Friday, November 16, 2012

In Ruby, private methods are visible in derived classes


    class Base
    private
      def hello
      end
    end
then methods in the derived class can call it:

    class Derived < Base
      def say
        hello # this is allowed in Ruby
      end
    end 
 
Simply to say this :
in C++ and OOP languages, “private” means “private to this class”, 
while in Ruby it means “private to that instance”. Again here class is itself an object :-)

Thats means private method will have only one receiver that is self.