Pete Elmore
9/13/2006 3:38:00 AM
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.