Hi --

On Sun, 7 Jul 2002, Dave Thomas wrote:

>
>
> Working with CGI forms and databases, it's something of a pain having
> to do
>
>    string = cgi['field'][0]
>
>    if string.nil? || string.empty?
>       error "Please specify a value for 'field'"
>    end
>
>    etc etc...
>
> Would it be silly to have a predefined method:
>
>    def nil.empty?
>       true
>    end

My first thought (slightly devil's advocate-ish) is that you could do:

  if string.to_s.empty?  ...

Also it feels to me that the idea of a Boolean empty? test for nil
implies that there's the logical possibility of nil not being empty.
In other words, emptiness might be too rich a characteristic for nil
to have, or something like that.

Just thinking out loud -- back at ya --


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav