From: "E. Saynatkari" Date: 2006-02-24T07:25:02+09:00 Subject: Re: Private methods and self: James Byrne wrote: > > FOR ruby 1.8.4 (2005-12-24) [i386-linux]: > > #-------------------------------------------------------------------------- > def foo1 > self.bar > end > > def foo2 > bar > end > > def bar > puts "In bar" > end > > private :bar > > if __FILE__ == $0 > > foo2 -> 'In bar' > foo1 -> 'NoMethodError: private method `bar' called for main:Object' > > #-------------------------------------------------------------------------- > > Why the difference in treatment between the explict self reciever and > the implict self receiver? Private methods are not allowed to have an explicit receiver (using the 'self' there is like going out of the object and then sending the message). The only exception to this rule are writer methods (def foo=(); ...; end) because without the self., foo = x is always interpreted as an assignment to a local variable. > Regards, > Jim E -- Posted via http://www.ruby-forum.com/.