[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem with example from pickax book

Ben Edwards

7/13/2007 2:51:00 PM

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 = 5*60 # 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
--
Ben Edwards - Bristol, UK
http://www.flickr.com/photos/413... - have a look at my pics
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles...
(email address this email is sent from may be defunct)

3 Answers

Axel Etzold

7/13/2007 3:21:00 PM

0

Dear Ben,

> irb(main):040:0* class SongList
> irb(main):041:1> MAX_TIME = 5*60 # 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
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/mult...

Florian Groß

7/13/2007 3:29:00 PM

0

On Jul 13, 4:51 pm, "Ben Edwards" <funkyt...@gmail.com> wrote:
> 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 = 5*60 # 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

Songlist needs to be SongList. Or just change it to "self". :)


Ben Edwards

7/13/2007 3:30:00 PM

0

On 13/07/07, Axel Etzold <AEtzold@gmx.de> wrote:
> Dear Ben,
>
> > irb(main):040:0* class SongList
> > irb(main):041:1> MAX_TIME = 5*60 # 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

> Best regards,
>
> Axel
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kanns mit allen: http://www.gmx.net/de/go/mult...
>
>


--
Ben Edwards - Bristol, UK
http://www.flickr.com/photos/413... - have a look at my pics
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles...
(email address this email is sent from may be defunct)