From: Justin Collins Date: 2012-06-30T01:01:45+09:00 Subject: Re: Accessor Methods with a Twist On 06/29/2012 08:33 AM, Doug Jolley wrote: > I am surprised that the code shown below returns, 'Doug'. I would > expect that it would return, 'Fred'. Can someone please tell me why? > > @name = 'Doug' > > def name=(name) > @name = name > end > def name() > return @name > end > > name=('Fred') > puts(name()) > > Thanks. > > ... doug > > P.S. - Please understand that this question is academic to help me > understand things. Naturally, I would not do this in practice. Thanks > again. > `name=('Fred)` is not calling your `name=` method. It's parsed as `name = 'Fred'`, i.e. a local variable assignment. You can see this if you do `puts name` vs. `puts name()` To achieve what you expect, you can use `self.name = 'Fred'` -Justin