where does song.name come from?

C

chen li

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

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 
M

Morton Goldberg

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.

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::mad:name. It has
nothing to do with the method Module::name.

Regards, Morton
 
P

Phrogz

chen said:
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
...
 
L

Li Chen

Gavin said:
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
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top