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
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
On 2007-02-22, S. Robert J. [email protected] 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 H.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs