Problem with example from pickax book


#1

Working through the Pickax Ruby programing book and cant get the
following example ‘compile’:-

irb(main):040:0* class SongList
irb(main):041:1> MAX_TIME = 560 # 5 minutes
irb(main):042:1>
irb(main):043:1
def Songlist.is_too_long(song)
irb(main):044:2> return song.duration > MAX_TIME
irb(main):045:2> end
irb(main):046:1> end
(irb):41: warning: already initialized constant MAX_TIME
NameError: uninitialized constant SongList::Songlist
from (irb):43
from :0

Any idea why?

Ben


#2

Dear Ben,

irb(main):040:0* class SongList
irb(main):041:1> MAX_TIME = 560 # 5 minutes
irb(main):042:1>
irb(main):043:1
def Songlist.is_too_long(song)
^^^^^^^^^

Just leave out the underlined “Songlist.”
Best regards,

Axel


#3

On Jul 13, 4:51 pm, “Ben E.” removed_email_address@domain.invalid wrote:

(irb):41: warning: already initialized constant MAX_TIME
NameError: uninitialized constant SongList::Songlist

Songlist needs to be SongList. Or just change it to “self”. :slight_smile:


#4

On 13/07/07, Axel E. removed_email_address@domain.invalid wrote:

Dear Ben,

irb(main):040:0* class SongList
irb(main):041:1> MAX_TIME = 560 # 5 minutes
irb(main):042:1>
irb(main):043:1
def Songlist.is_too_long(song)
^^^^^^^^^

Just leave out the underlined “Songlist.”

Its actually supposed to be a class method, but ive spotted the error.
It should be SongList, not Songlist (the L needs to be upper case).

Ta,
Ben