Newbie - error while trying subclass

D

David A. Black

Hi --

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
^

karaokeSong isn't a constant. Try KaraokeSong (uppercase 'K').


David
 
R

Rubystudent

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
 
T

Tim Greer

Rubystudent said:
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.
 
M

Mike Cargal

Try capitalizing karaokeSong

the first error is complaining about the class name not being CONSTANT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top