From: Eric Hodel Date: 2007-10-11T16:17:45+09:00 Subject: Re: what does print call internally? On Oct 10, 2007, at 19:58 , 7stud -- wrote: > Eric Hodel wrote: >> On Oct 10, 2007, at 15:31 , Martin DeMello wrote: >> >>> => foo >> it calls #to_s. > > class Dog > def to_s > print "dog" > end > end > > d = Dog.new > > print d > puts > > puts d > > --output:-- > dog# > dog# In IO#write, if #to_s returns nil, rb_any_to_s() gets called, which returns "#<#{self.class}:0x#{object_id.to_s 16}>", which gets printed instead of your broken #to_s. -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars