On Tue, May 29, 2007 at 09:55:04PM +0900, [email protected] wrote:
My understanding of puts is that it puts the result of to_s.
puts n and puts n.to_s are the same then and should in my example
print the same.
But they don’t and that is for me a bit annoying because I thought I
understood what was going on.
Yes, but what do you expect “puts” to do when it calls to_s on an
but the result is not a string? Raise an exception perhaps? It’s more
friendly for puts to have a fallback behaviour.
Note: there’s one other special case I’m aware of. If you do
then you get the string “nil” printed (plus newline). However, nil.to_s
the empty string.