Forum: Ruby puts nil

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
53a1f0aba6f0489d49f5e6fc3df323fa?d=identicon&s=25 Robert James (robertjames)
on 2007-02-23 00:01
(Received via mailing list)
puts nil outputs "nil".  Shouldn't it output "" (ie, nothing), which
is nil.to_s?

RDoc (for IO#print, referenced by #puts):
Objects that aren't strings will be converted by calling their to_s
method
7fd7ef91196768cae4e7ca215c8a0a8f?d=identicon&s=25 Jeremy Henty (Guest)
on 2007-02-23 11:21
(Received via mailing list)
On 2007-02-22, S. Robert James <srobertjames@gmail.com> wrote:

> puts nil outputs "nil".  Shouldn't it output "" (ie, nothing), which
> is nil.to_s?

The source code specifically checks for the nil object and outputs
"nil" instead of nil.to_s .  It's clearly a deliberate decision by the
developers to make nil a special case.  The docs don't mention it, and
I agree that they should.

Regards,

Jeremy Henty
This topic is locked and can not be replied to.