The python __repr__ function is fancy as it is called when print OBJECT is used automatically.
Is there a Ruby equivalent? I thought it was to_s, but I had an OBJECT OB, it does not seem to call the to_s method.
Added
Something is wrong with me, p OBJECT seems to be calling the to_s method as follows. I have some tips from my answers to my other question. - Question of Ruby's to_s method (from Axx 2nd edition book)
# 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
python ruby
prosseek
source share