First wall

I ran the SongList example in “Programming Ruby” and got this error on the
list.
append(Song.new(‘title1’,…) statement:

“uninitialized constant Song (NameError)”

Can someone point me in the right direction to solve this?

Ted

  append(Song.new('title1',...) statement:

"uninitialized constant Song (NameError)"

Well, this is because you have forgotten to include the definition for the
class Song, something like :

   class Song
      @@plays = 0
      def initialize(name artist, duration)
         @name = name
         @artist = artist
         @duration = duration
         @play = 0
      end
      
      # etc, etc, etc
   end

   class SongList
      def initialize
         @songs = Array.new
      end

      def append(aSong)
         @songs.push(aSong)
         self
      end
   end

   list = SongList.new
   list.
      append(Song.new('title1', 'artist1', 1)
   # etc, etc, etc

or put the definition of the class Song in a file 'song.rb' then write

   require 'song'

   class SongList
      # erc, etc, etc
   end

   list = SongList.new
   list.
      append(Song.new('title1', 'artist1', 1
   # etc, etc, etc

Guy Decoux

Guy: Heh… it worked! Thanks a bunch. Now, if you ever need help with
S/370 assembler or COBOL, I’ll be more than happy to help. ;->

So simple. But I’m just starting out in OO languages.

···

Well, this is because you have forgotten to include the definition for the
class Song, something like :