From: ChrisH Date: 2006-07-06T23:52:43+09:00 Subject: Re: attribute reader Just Another Victim of the Ambient Morality wrote: > "Robert Klemme" wrote in message > news:4h1o45F1p7ma2U1@individual.net... > > > > class Times > > attr_accessor :time > > > > def time_seconds > > self.time.sec > > end > > > > def now > > self.time = Time.now > > end > > end > > As an aside, I'm still learning Ruby and am curious to know why you > choose to use self.time instead of @time. Is there some sort of gatcha > about using instance variables (object variables?) that I don't know about? > Thank you... attr_accessor :time creates an attribute (@time) and two accessor methods: def time #return the value in our attribute @time end def time=(other) #set the attribute to the given value @time = other end self.time.sec calls the time method of self to get the value of @time and calls the method sec on it self.time = Time.now assigns the value of Time.now to the attribute via the time= method of self. cheers