From: 7stud -- Date: 2007-10-11T21:03:39+09:00 Subject: Re: what does print call internally? Martin DeMello wrote: > On 10/10/07, Konrad Meyer wrote: >> >> I'm guessing puts/print treat nil as a special case, but I may be wrong. > > That's quite counterintuitive, though. If true, the question becomes > "why?" - I can't see any useful purpose it'd serve, save maybe > debugging. > > martin pickaxe2, p. 131: "With a couple of exceptions, every object you pass to puts and print is converted to a string by calling that object's to_s method. If for some reason the to_s method doesn't return a valid string, a string is created containing the object's class name and ID.... The exceptions are simple, too. The nil object will print as the string 'nil', and an array passed to puts will be written as if each of its elements in turn were passed separately to puts." Eric Hodel wrote: > On Oct 10, 2007, at 19:58 , 7stud -- wrote: >> end >> 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. How do you get from puts/print to IO.write? -- Posted via http://www.ruby-forum.com/.