Forum: Ruby on Rails help : uninitialized constant Song

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
freaky fashion (Guest)
on 2006-04-08 08:03
(Received via mailing list)
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
Agnieszka F. (Guest)
on 2006-04-08 13:37
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
This topic is locked and can not be replied to.