Ruby's to_s method question (from Axe book 2nd edition)
Posted
by prosseek
on Stack Overflow
See other posts from Stack Overflow
or by prosseek
Published on 2010-04-12T20:13:55Z
Indexed on
2010/04/12
20:23 UTC
Read the original article
Hit count: 199
According to the axe book (2nd edition), we can use to_s as follows.
class Song def to_s "Song" end end song = Song.new() song.to_s
But, it doesn't give me anything, in order to print something to the stdout, I should run
def to_s p "Song" end
Is there any change since the ruby 1.8.2 when the book was written for? My ruby version info is 1.8.7 for Mac.
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
© Stack Overflow or respective owner