A
Adrian Arlechin
I am learning from Programming Ruby wich comes with Ruby instalation.
In the chapter about containers - Implementing a SongList Container
I took the code in NetBeans like follows:
require 'Baza.rb' #here is my Song class
class SongList < Song
def initialize
@songs = Array.new
end
end
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)).
append(Song.new('title3', 'artist3', 3)).
append(Song.new('title4', 'artist4', 4))
############# Here is my problem
puts list.to_a ?????????
What line must I have here to have at terminal the array that is created
in the SongList like this:
Song: title1--artist1 (1)
Song: title2--artist2 (2).... etc , so that I can work with it?
and/or to see the list elements with list[0, 2]
Thanks
In the chapter about containers - Implementing a SongList Container
I took the code in NetBeans like follows:
require 'Baza.rb' #here is my Song class
class SongList < Song
def initialize
@songs = Array.new
end
end
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)).
append(Song.new('title3', 'artist3', 3)).
append(Song.new('title4', 'artist4', 4))
############# Here is my problem
puts list.to_a ?????????
What line must I have here to have at terminal the array that is created
in the SongList like this:
Song: title1--artist1 (1)
Song: title2--artist2 (2).... etc , so that I can work with it?
and/or to see the list elements with list[0, 2]
Thanks