From: Robert Dober Date: 2007-01-20T17:54:36+09:00 Subject: Re: attr_accessor weirdness, or something ------=_Part_169680_9735783.1169283274559 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/20/07, CBlair1986 wrote: > > > > def update_timer > timer = Time.now you are assigning to a local variable, as you found out yourself you can assign to the instance variable @timer = Time.now if you want to use the accessor method you have to write this as self.timer = Time.now end > end > > But, as simple as it looks, it doesn't work. I'll make a new Test > object and call update_timer all I want, and it won't update. It seems > a bit counter-intuitive. I've made an accessor for a variable that I > declare when initialized, and then go to change it, and it doesn't > work. > > However, if I change the 'timer' in update_timer to '@timer', it works > perfectly fine. Why is this? This is a trap lots of folks falls in, Ruby just prefers autocreation of local variables to method resolution. HTH Robert Thank you! > > > -- "The best way to predict the future is to invent it." - Alan Kay ------=_Part_169680_9735783.1169283274559--