From: MonkeeSage Date: 2007-12-18T10:10:03+09:00 Subject: Re: self and private setter On Dec 17, 6:44 pm, Paul wrote: > A private method cannot be called with an explicit receiver -- even > self -- except when calling a private setter method, because otherwise > an assignment to a local variable will be assumed. > > For example: > ----------------------- > class Q > > def a1 > @p = nil > self.p=(3) > @p > end > > def a2 > @p = nil > p=(3) > @p > end > > private > > def p=(obj) > @p = obj > end > end > ----------------------- > > CONSOLE > > >> Q.new.a1 > => 3 > >> Q.new.a2 > > => nil > ----------------------- > > Since there is already this exception to the rule, why not allow > explicitly using self for ALL private methods? What harm can be done? I'm pretty sure that's the difference between protected and private visibility; protected lets you use an explicit receiver (and maybe other things like children classes can also access the method?). But if you need to use private methods, you can always call them with an explicit receiver by using #send. Regards, Jordan