The __repr__
function of python is fancy as it is called when print OBJECT is used automatically.
Is there a ruby equivalence for it? I thought it was to_s, but, I had p OBJECT doesn't seem to call the to_s method.
=== Added ===
I got something wrong, p OBJECT seems to call to_s method as follows. I got some hints from my the answers to my other question. - http://stackoverflow.com/questions/2625093/rubys-to-s-method-question-from-axe-book-2nd-edition
# Sample code from Programing Ruby, page 24
class Song
def to_s
"Song"
end
end
class Songson < Song
def to_s
super + "<Songson>"
end
end
song = Songson.new()
p song