On Sep 7, 2007, at 2:44 PM, Nasir Khan wrote:

> IMHO nil.to_s => "", nil.to_i => 0 and nil.to_a => [] are potential  
> sources
> of confusion and bugs.
>
> If anywhere in your code you have statement like
>
> x = y.to_s then you will have to be careful to replace it with
> x = y.nil? ? nil : y.to_s
>
> An empty string equivalence of nil seems untuitive to me, all of these
> should just return nil.
> Is it just me or are there others who have also feel like this?

This has come up on the mailing list before, and there are some  
people who agree with you. I, for one, prefer it the way it is  
because it lets me write code like:

<code>
n =  4
n.downto(0) do |k|
    puts "#{k} bottle#{'s' if k != 1} of beer"
end
</code>

<result>
4 bottles of beer
3 bottles of beer
2 bottles of beer
1 bottle of beer
0 bottles of beer
</result>

Regards, Morton