Hi --

On Tue, 21 Nov 2006, El Gato wrote:

> Bernard Kenik wrote:
>>
>> this is a ruby gotcha
>>
>> the only thing that returns false or false or nil
>>
>> 0 , '0', '''', an empty array, or an empty hash all evaluate to true
>
> Saying it's a "gotcha" makes it sound like the behavior is wrong.  Some
> would say that only false should be false.  Me, I like that nil is
> false, but I sure as hell don't want 0 or '' or [] or {} to be false.
> It behaves well -- that's not a gotcha -- that's just good common sense.
>
> I can't quite tell what you're looking for exactly, but String#match is
> probably it.  (I don't like the =~ perlism myself).

I don't either, but I've reluctantly had to accept that it's faster
than #match, at least in the comparisons I've seen.  Of course that
doesn't matter unless it matters, so to speak.


David

-- 
                   David A. Black | dblack / rubypal.com
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org