From: Matthew Desmarais Date: 2005-12-14T02:31:33+09:00 Subject: Re: Private attribute or accessor? Sam Kong wrote: >Hi! > >See the following codes. > >[1] >class C > attr_accessor :a > def f(v) > @a = v > ... > end >end > >[2] >class C > attr_accessor :a > def f(v) > a = v > ... > end >end > > >[1] and [2] work exactly same. >I wonder which way is more proper. > >In my opinion, if there're accessors (getter and setter), using them in >the class is better than directly accessing the instance data. >However, most codes I've seen access the data directly. > >What do you think? > >Sam > > Hi Sam, Just a quick point: your examples don't work the same way. In [2], you'll want to replace a = v with self.a = v. Regards, Matthew