From: Mike Onofrietto Date: 2011-02-12T11:02:46+09:00 Subject: Re: attr_reader vs Objects and Attributes Brian, Thanks that helps. The code I pasted was from the Thomas & Hunt manual, but maybe I took it out of context. Their presentation of the associated values further confused me. aSong.artist » "Fleck" aSong.name » "Bicylops" aSong.duration » 260 Yes - I was thinking attr_accessor was some combination of attr_reader, and attr_writer. Thanks again, Mike Brian Candler wrote in post #980745: > > You only defined reader methods. You also need: > > def name=(name) > @name=name > end > def artist=(artist) > @artist=artist > end > ... etc > > 'attr_accessor' gives you both reader and writer methods. 'attr_reader' > gives you just the reader ones (as in your code), and 'attr_writer' > gives just the writer ones. > > In future, it would be very helpful if you could post the exact error > message you see. In your case it was probably something like > NoMethodError - unknown method 'artist=', which would have immediately > pinpointed the error. > > Regards, > > Brian. -- Posted via http://www.ruby-forum.com/.