hi
I get an error
"NameError: undefined method 'push' for nil from append"
as I'm working thru the Prag prog ruby book.
"""We'll start our class with a basic initialize method, which creates
the Array we'll use to hold our songs and store a reference to it in the
instance variable @songs
class SongList
def initialize
@songs = Array.new
end
end
The SongList#append method adds the given song to the end of teh @songs
array. It also
returns self, a reference to the current SongList object. This is a
useful convention, as it allows us to chain together multiple calls to
appand...
class Songlist
def append(aSong)
@songs.push(aSong)
self
end
end
list = SongList.new
list.
append(Song.new('title1', 'artist1', 1)).
append(Song.new('title2', 'artist2', 2)) """
reports the error.
I've worked through all the example code and have been very impressed.
It is
very instructive and is the only book I've seen that tries to teach
using a real model.
I'm writting all the code in irb. Also, a test like
cSong = Song.new('title', 'artist', 245)
works fine.