puts nil generates "nil\n"

B

Brian Candler

$ ruby -v
ruby 1.8.2 (2004-07-29) [i386-freebsd5]
$ ruby -e 'puts nil'
nil
$ ruby -e 'puts nil.to_s'

$

This is strange and seems to conflict with the documentation in ri, which
says:

- Kernel.puts is the same as $stdout.puts

- IO.puts says

Writes the given objects to _ios_ as with +IO#print+.

- IO.print says

Objects that aren't strings will be converted
by calling their +to_s+ method.

So is 'nil' a special case for puts/print? Is the documentation wrong?

Regards,

Brian Candler.
 
T

ts

B> So is 'nil' a special case for puts/print?

nil is a special case for #print, #puts


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top