Hi,
I’m facing the following issue.
I have a class A in that i tried instantiating another class B.
but got uninitialized constant B error…Any idea how to over come
this.
Here is my code.
class SongList
#initialize the array
def initialize
@songs=Array.new
end
def aSong(aSong)
@songs.push(aSong)
self
end
def deleteFirst
@songs.shift
end
def deleteLast
@songs.pop
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))
thnx
FF
freaky fashion wrote:
Hi,
I’m facing the following issue.
I have a class A in that i tried instantiating another class B.
but got uninitialized constant B error…Any idea how to over come
this.
Here is my code.
class SongList
#initialize the array
def initialize
@songs=Array.new
end
def aSong(aSong)
@songs.push(aSong)
self
end
def deleteFirst
@songs.shift
end
def deleteLast
@songs.pop
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))
thnx
FF
Hi,
the error you’re receiving is probably because the class song is in a
different file, in which case you should add
require ‘song’ (provided that file is called song.rb)
at the top of the file where you have your song list class. If you put
them both in one fileyou wouldn’t need this.
Also, there’s a problem with the method ‘append’ which you have not
defined in song list - possibly method aSong is supposed to be called
append since that’s what it seems to be doing.
–
Agnieszka