[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

puts nil

S. Robert James

2/22/2007 10:57:00 PM

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

1 Answer

Jeremy Henty

2/23/2007 10:19:00 AM

0

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