# Help : uninitialized constant Song

**URL:** <https://www.ruby-forum.com/t/help-uninitialized-constant-song/57230>\
**Category:** Rails\
**Created:** [April 8, 2006, 6:03am UTC](https://www.ruby-forum.com/t/help-uninitialized-constant-song/57230 "2006-04-08T06:03:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![freaky\_fashion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c68b51/32.png) [@freaky\_fashion](https://www.ruby-forum.com/u/freaky_fashion)\
**Post date:** [April 8, 2006, 6:03am UTC](https://www.ruby-forum.com/t/help-uninitialized-constant-song/57230/1 "2006-04-08T06:03:27Z")

</div>

Hi,  
I’m facing the following issue.

```
I have a class A in that i tried instantiating another class B.

```

but got uninitialized constant B error…Any idea how to over come  
this.

Here is my code.

* * *

class SongList

#initialize the array

```
 def initialize
@songs=Array.new
 end

 def aSong(aSong)
@songs.push(aSong)
self
 end

 def deleteFirst
@songs.shift
 end

 def deleteLast
@songs.pop
 end

```

end

## list =SongList.new list. append(Song.new(‘title1’, ‘artist1’, 1)). append(Song.new(‘title2’, ‘artist2’, 2)). append(Song.new(‘title3’, ‘artist3’, 3)). append(Song.new(‘title4’, ‘artist4’, 4))

thnx  
FF

---

<div class="post-metadata">

**Author:** ![freaky\_fashion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c68b51/32.png) [@freaky\_fashion](https://www.ruby-forum.com/u/freaky_fashion)\
**Post date:** [April 8, 2006, 11:37am UTC](https://www.ruby-forum.com/t/help-uninitialized-constant-song/57230/2 "2006-04-08T11:37:04Z")

</div>

freaky fashion wrote:

> Hi,  
> I’m facing the following issue.
> 
> ```
> I have a class A in that i tried instantiating another class B.
> 
> ```
> 
> but got uninitialized constant B error…Any idea how to over come  
> this.
> 
> Here is my code.
> 
> * * *
> 
> class SongList
> 
> #initialize the array
> 
> ```
> def initialize
> @songs=Array.new
> end
> 
> def aSong(aSong)
> @songs.push(aSong)
> self
> end
> 
> def deleteFirst
> @songs.shift
> end
> 
> def deleteLast
> @songs.pop
> end
> 
> ```
> 
> end
> 
> ## list =SongList.new list. append(Song.new(‘title1’, ‘artist1’, 1)). append(Song.new(‘title2’, ‘artist2’, 2)). append(Song.new(‘title3’, ‘artist3’, 3)). append(Song.new(‘title4’, ‘artist4’, 4))
> 
> thnx  
> FF

Hi,

the error you’re receiving is probably because the class song is in a  
different file, in which case you should add  
require ‘song’ (provided that file is called song.rb)  
at the top of the file where you have your song list class. If you put  
them both in one fileyou wouldn’t need this.

Also, there’s a problem with the method ‘append’ which you have not  
defined in song list - possibly method aSong is supposed to be called  
append since that’s what it seems to be doing.

–  
Agnieszka
