# Newbie - error while trying subclass

**URL:** <https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622>\
**Category:** Ruby\
**Created:** [December 14, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622 "2008-12-14T20:25:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubystudent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubystudent](https://www.ruby-forum.com/u/rubystudent)\
**Post date:** [December 14, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622/1 "2008-12-14T20:25:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rubystudent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubystudent](https://www.ruby-forum.com/u/rubystudent)\
**Post date:** [December 14, 2008, 8:28pm UTC](https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622/2 "2008-12-14T20:28:43Z")

</div>

Hi –

On Mon, 15 Dec 2008, 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  
> ^

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

David

---

<div class="post-metadata">

**Author:** ![rubystudent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubystudent](https://www.ruby-forum.com/u/rubystudent)\
**Post date:** [December 14, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622/3 "2008-12-14T20:40:27Z")

</div>

Rubystudent wrote:

> 

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.

---

<div class="post-metadata">

**Author:** ![rubystudent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubystudent](https://www.ruby-forum.com/u/rubystudent)\
**Post date:** [December 14, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622/4 "2008-12-14T21:22:39Z")

</div>

Try capitalizing karaokeSong

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

---

<div class="post-metadata">

**Author:** ![rubystudent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@rubystudent](https://www.ruby-forum.com/u/rubystudent)\
**Post date:** [December 14, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/newbie-error-while-trying-subclass/155622/5 "2008-12-14T20:42:12Z")

</div>

David, Tim - Thanks a lot.  
It worked.

Sunil
