# Where does song.name come from?

**URL:** <https://www.ruby-forum.com/t/where-does-song-name-come-from/80519>\
**Category:** Ruby\
**Created:** [December 28, 2006, 4:56am UTC](https://www.ruby-forum.com/t/where-does-song-name-come-from/80519 "2006-12-28T04:56:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 28, 2006, 4:56am UTC](https://www.ruby-forum.com/t/where-does-song-name-come-from/80519/1 "2006-12-28T04:56:52Z")

</div>

Hi all,

On page 49 of Pickaxe 2 are some scripts:

class Songlist  
def with\_title(title)  
@songs.find{|song| title==song.name}  
end  
end

I just wonder where the method “name” comes from and  
what its purpose is here. I check for Index on page  
809 and find “name” is mentioned in class Module only,  
which returns the name of module mod.

Thanks,

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 28, 2006, 6:27am UTC](https://www.ruby-forum.com/t/where-does-song-name-come-from/80519/2 "2006-12-28T06:27:06Z")

</div>

On Dec 27, 2006, at 10:55 PM, chen li wrote:

> I just wonder where the method “name” comes from and  
> what its purpose is here. I check for Index on page  
> 809 and find “name” is mentioned in class Module only,  
> which returns the name of module mod.

Very much earlier in the book (p. 26 in the PDF version) the class  
Song was defined as follows:

class Song  
def name  
@name  
end  
def artist  
@artist  
end  
def duration  
@duration  
end  
end

That’s where ‘name’ comes from. It’s a reader method and it’s purpose  
is to return the value of the instance variable Song::@name. It has  
nothing to do with the method Module::name.

Regards, Morton

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 28, 2006, 6:41am UTC](https://www.ruby-forum.com/t/where-does-song-name-come-from/80519/3 "2006-12-28T06:41:08Z")

</div>

chen li wrote:

> On page 49 of Pickaxe 2 are some scripts:
> 
> class Songlist  
> def with\_title(title)  
> @songs.find{|song| title==song.name}  
> end  
> end
> 
> I just wonder where the method “name” comes from and  
> what its purpose is here.

Earlier in the book there is:

class Song  
def name  
@name  
end  
…

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 28, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/where-does-song-name-come-from/80519/4 "2006-12-28T15:01:59Z")

</div>

Gavin K. wrote:

> > 
> 
> Earlier in the book there is:
> 
> class Song  
> def name  
> @name  
> end  
> …

Thanks.

The methods about class Song are everywhere on different pages.  
Sometimes I get lost. I think it would be nice if somewhere in the  
book(such as appendix) class Song and all its methods are put together.

Li
