From: "Hal E. Fulton" Date: 2000-10-11T14:52:02+09:00 Subject: [ruby-talk:5413] Re: Object.foo, setters and so on Ahh. So we're not talking about the toplevel. Thanks. Hal ----- Original Message ----- From: Dave Thomas To: ruby-talk ML Sent: Tuesday, October 10, 2000 10:16 PM Subject: [ruby-talk:5412] Re: Object.foo, setters and so on > "Hal E. Fulton" writes: > > > What does this entry in the FAQ mean? > > say you have > > class Dave > > def fred > @fred > end > > def fred=(n) > @fred = n > end > > def test > fred = 99 > end > end > > You might be tempted to think that the line 'fred = 99' in method > 'test' calls the method 'fred='. After all, method calls in functional > form have 'self.' implicitly prepended, right? > > Unfortunately not. In this case, Ruby will look at 'fred = 99' and > simply assign 99 to a local variable 'fred'. To invoke the setter > method, you need to make the self. explicit: > > > def test > self.fred = 99 > end > > > Regards > > > Dave >