"Hal E. Fulton" <hal9000 / hypermetrics.com> 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