Ruby Syntax Question from (pickaxe book)
russel morgan
1 post
|
I was following the examples in the pickaxe book and I hit one error at run time I was curious about. When I try the chained append method for the below class like the book I get the following error:
Chain Code: list.append(s1).append(s2) If I do it “Traditionally” like thus: It works fine… I have included the relevant class below, what am I doing wrong? This example appears on Page 48 of the second edition of <u>Programming Ruby</u> The code I have input:(relevant section) class SongList
def initialize
@songs = Array.new
end
def append(song)
@songs.push(song)
end
def delete_first
@songs.shift
end
def delete_last
@songs.pop
end
def [](index)
@songs[index]
end
def to_s
“This song list contains songs”
end
|
Ben Alpert
1 post
|
Add a line to your append definition:
|
2 posts, 2 voices
