From: Morton Goldberg Date: 2006-10-29T04:43:37+09:00 Subject: Re: nil.to_s != "nil" On Oct 28, 2006, at 3:05 PM, Vidar Hokstad wrote: > > Eero Saynatkari wrote: >> On 2006.10.28 00:20, Phrogz wrote: >>> You are correct that "" != nil, but "nil" != nil also. >>> What are you really trying to achieve? And, did you know that >>> nil.inspect yields "nil"? >> >> Yes. I want consistency. > > It is consistent. "to_s" returns a string representation of the > value(s) of the object you call it on. > > The value of the object nil is _nothing_ and the empty string is a > sensible representation of that. As well as sensible, it can be useful: #! /usr/bin/env ruby -w def bottles(n) "#{n} bottle#{'s' if n != 1} of beer on the wall" end bottles(99) # => "99 bottles of beer on the wall" bottles(1) # => "1 bottle of beer on the wall" Regards, Morton