From: John Legate Date: 2006-09-13T13:13:43+09:00 Subject: Re: Newbie Alert D'OH! I mean, thanks very much to all of you who helped me solve this problem. I'm also kind of new at searching for answers on a Help Forum like this, and I'm pleasantly surprised and impressed with how quickly the answer can be found in this venue. 1337p337 wrote: > This is actually easy to fix. '+' is an undefined method for > nil:Nilclass, which means that the super on line 22 is returning nil. > 'super' refers to the to_s of the parent class which is, Song#to_s: > >> 01 class Song > ... >> 07 def to_s >> 08 puts "Song: #{@name}--#{@artist} (#{@duration})" >> 09 end >> 10 end > > The problem is the 'puts'. puts prints a string and a "\n" to > standard out and returns nil. You actually don't usually want to_s to > print anything, so if you change Song#to_s to read > def to_s > "Song: #{@name}--#{@artist} (#{@duration})" > end > That will fix the bug, but your program won't print anything, because > aSong.to_s will just return a string (which is what you want). So > you'll need to change lines 13 and 14: > >> 13 print "aSong.to_s ==> " >> 14 aSong.to_s > > to > print "aSong.to_s ==> " + aSong.to_s + "\n" > or > puts "aSong.to_s ==> #{aSong.to_s}" > and do something similar with lines 26 and 27. -- Posted via http://www.ruby-forum.com/.