[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Newbie - error while trying subclass

Rubystudent

12/14/2008 7:23:00 PM

I am trying to subclass in my code (see below). But I am getting the
following error while running the code.

song.rb:12: class/module name must be CONSTANT
class karaokeSong < Song
^
song.rb:23: warning: don't put space before argument parentheses

Not able to figure why "<" is not being accepted for subclassing. I am
using 1.8.6 version on windows. Pls. help

-----------------------------------------------------------------------------------------
class Song
def initialize (name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
def to_s
"Song: #{@name}--#{@artist} #{@duration}"
end
end

class karaokeSong < Song
def initialize (name, artist, duration, lyrics)
super(name, artist, duration)
@lyrics = lyrics
end
end

aSong = karaokeSong.new ("Bicyclops", "Fleck", 260, "And, now the")
puts aSong.inspect
puts aSong.to_s
3 Answers

Tim Greer

12/14/2008 7:31:00 PM

0

Rubystudent wrote:

> I am trying to subclass in my code (see below). But I am getting the
> following error while running the code.
>
> song.rb:12: class/module name must be CONSTANT
> class karaokeSong < Song
> ^
> song.rb:23: warning: don't put space before argument parentheses
>
> Not able to figure why "<" is not being accepted for subclassing. I am
> using 1.8.6 version on windows. Pls. help
>

What version of ruby are you using?

See below for changes:

> class karaokeSong < Song

class KaraokeSong < Song

> aSong = karaokeSong.new ("Bicyclops", "Fleck", 260, "And, now the")

aSong = KaraokeSong.new("Bicyclops", "Fleck", 260, "And, now the")

That should remedy the problem.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!

Rubystudent

12/14/2008 7:40:00 PM

0

David, Tim - Thanks a lot.
It worked.

Sunil

msnews.microsoft.com

12/14/2008 8:15:00 PM

0

Try capitalizing karaokeSong

the first error is complaining about the class name not being CONSTANT.
On Dec 14, 2008, at 2:17 PM, Rubystudent wrote:

> I am trying to subclass in my code (see below). But I am getting the
> following error while running the code.
>
> song.rb:12: class/module name must be CONSTANT
> class karaokeSong < Song
> ^
> song.rb:23: warning: don't put space before argument parentheses
>
> Not able to figure why "<" is not being accepted for subclassing. I am
> using 1.8.6 version on windows. Pls. help
>
> -----------------------------------------------------------------------------------------
> class Song
> def initialize (name, artist, duration)
> @name = name
> @artist = artist
> @duration = duration
> end
> def to_s
> "Song: #{@name}--#{@artist} #{@duration}"
> end
> end
>
> class karaokeSong < Song
> def initialize (name, artist, duration, lyrics)
> super(name, artist, duration)
> @lyrics = lyrics
> end
> end
>
> aSong = karaokeSong.new ("Bicyclops", "Fleck", 260, "And, now the")
> puts aSong.inspect
> puts aSong.to_s
>