Total newbie, to_s method and format strings

I am reading the Pragmatic programmer book, but can’t get the
to_s method in the first class in the book (Song) to work as
promised, it just delivers the format string verbatim when called.

I also tried the earlier examples which plays with a function using as
format string to say goodnight to various people, these examples also
just return the format string.

Here is my class definition (in case there is something glaringly
obvious that I have done differently from the examples but am unable
to see myself).

class Song
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
def to_s
"Song: #(@name)–#(@artist) (#(@duration))"
end
end

The version I am running is:
ruby 1.6.7 (2002-03-01) [i586-mswin32]

on win2k pro

···

Vennlig hilsen

Syver Enstad

syver-en@online.no wrote in message news:r8fwjkta.fsf@online.no…

Here is my class definition (in case there is something glaringly obvious

^^^^^^^^^^^^

Yes

that I have done differently from the examples but am unable
to see myself).

"Song: #(@name)--#(@artist) (#(@duration))"
                ^                  ^                ^

This should be curly braces { }, like so:

     "Song: #{@name}--#{@artist} (#{@duration})"

HTH,

– Shanko

“Shashank Date” ADATE@kc.rr.com writes:

"Song: #(@name)--#(@artist) (#(@duration))"
                ^                  ^                ^

This should be curly braces { }, like so:

     "Song: #{@name}--#{@artist} (#{@duration})"

Ahh, great. In the print in the online version of Programming Ruby
they look almost identical.

···

Vennlig hilsen

Syver Enstad