From: Paul Lutus Date: 2006-10-22T17:50:13+09:00 Subject: Re: How to call private class method? estebanjang@gmail.com wrote: > Hi, > In the following code, how can I call "Hello.jane" method? > > class Hello > def Hello.jane > puts "I am jane" > end > private_class_method :jane > end Code: *************************** #!/usr/bin/ruby -w class Hello def Hello.jane puts "I am jane" end private_class_method :jane def Hello.access_from_world jane end end class Howdy < Hello def Howdy.from_child jane end end Hello::access_from_world Howdy::from_child Output: I am jane I am jane Explanation: ********************** First, because of how it has been declared, your method "Hello.jane" is a class method, not an instance method. It lives at the class level, so it must be called using the syntax reserved for class methods. Second, private methods can only be accessed by other methods of that class or derived classes, not from outside the class at all. This is by design. -- Paul Lutus http://www.arachnoid.com