From: Ken Bloom Date: 2007-09-03T01:10:10+09:00 Subject: Re: attr_reader On Sun, 02 Sep 2007 08:53:59 +0900, 7stud *** wrote: > And this confirms it: > > class Song > #attr_reader :name, :artist, :duration > end > > song = Song.new > > puts song.name > puts song.artist > puts song.duration > > puts song.fake > > --output:--- > r1test.rb:8: undefined method `name' for # (NoMethodError) There are two different things going on with attribute readers: attr_reader :foo creates a *method* to access the instance variable @foo. When you get a NoMethodError, because there's no such method. Supposing you create an instance variable @bar in some method, such as initailze, but have no attr_reader for it. You'll still get a NoMethodError because attr_reader wasn't called to create a method for it. --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/