James Edward Gray II <> wrote:
> > Bad example:
> >
> > while ( line = gets.chomp )
> > # work with line
> > end
>
> gets() returns a String or nil. nil does not support chomp(). When
> the chomp() is inside the while loop, this isn't an issue.
Often think it would be nice if "" and 0 were treated like nil. Such
functions could then return "". Heck, NilClass.to_s and NilClass.to_i
already return "" and 0 respectively.
Matz talks about premature optimizations. It looks like nil was made
this way for efficiency purposes! Can't say if it was premature
though.
Thanks for the answers!
Cheers,
Navin.