From: "Jesús Gabriel y Galán" Date: 2010-11-10T22:33:58+09:00 Subject: Re: "puts, if and unless" VS "nil" On Wed, Nov 10, 2010 at 2:26 PM, Edmond Kachale wrote: > Rubysters, > > I was sharing with some friends how to use if and unless. I wrote this > statement: *puts nil if nil* > and I got =>nil. (Which implies nothing was printed.) > > When I wrote: *puts nil unless nil* > I got: > nil > => nil > Which implies that puts output nil. > > My question is what is in *"nil"* that makes "*puts*" print "*nil"*? Or is > there any explanation to back this behaviour? It's in the implementation of puts: http://ruby-doc.org/core/classes/IO.src/M002252.html if (NIL_P(argv[i])) { line = rb_str_new2("nil"); } It specifically checks for nil arguments and prints "nil" in that case. Jesus.