From: Jeremy Bopp Date: 2010-10-07T07:52:45+09:00 Subject: Re: Missing @ for instace variable in class, but no error message On 10/6/2010 5:42 PM, Andrew Wagner wrote: > attr_accessor actually defines a public instance method, named 'a'. That > method can be called from both inside and outside the class. So, it's not an > error, it's perfectly valid. Beware of attempting to use the bare a= accessor within an instance method though. That will instead cause a variable named "a" to be created with the the method's scope rather than use the a= accessor, so @a won't be updated as expected. If you want to use the a= accessor, you need to use self.a = whatever. e.g.: class MyClass attr_accessor :a def change_a_bad(value) a = value end def change_a_good(value) self.a = value end end my_class = MyClass.new my_class.a = 1 my_class.change_a_bad(2) my_class.a # => 1 !!! my_class.change_a_good(2) my_class.a # => 2 :-) -Jeremy