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