From: ara howard Date: 2008-02-02T03:05:22+09:00 Subject: Re: @var = change to accessor method? Why? On Feb 1, 2008, at 10:54 AM, Day wrote: > class Thing > attr_accessor :a > > def do_something(arg) > @a = arg > end > end > > to... > > class Thing > attr_accessor :a > > def do_something(arg) > self.a = arg > end > end imagine that you now want to know everywhere @a is set, perhaps because you have a bug. you can start greping or simply def a= value p caller @a = 42 end done. also, i don't use 'self.a', but via attributes or fatter class C size 42 end where 'size' is a getter defined thusly def a *value if value.empty? @a else send 'a=', value.first end end which eliminates the oh so tiresome self. another huge advantage if using uniform access is that you can do things like class C attributes 'a, 'b', 'c' end p C.new.attributes => ['a', 'b' , 'c'] which is to say you can keep track of what state and object is likely to contain. making things like serialization trivial to write. regards. a @ http://codeforpeople.com/ -- it is not enough to be compassionate. you must act. h.h. the 14th dalai lama