Robert Klemme
3/28/2006 6:52:00 PM
Pistos Christou wrote:
> Victor Shepelev wrote:
>> if match_result
>> ...
>> end
>>
>> because in Ruby only nil and false are "false", where any other value
>> (including 0, '' and []) are "true".
>
> Yep, thank you to you and David. I forgot that I could rewrite it like
> that.
>
> Kevin wrote:
>> You could just do this...
>> if string =~ /(\w)/
>> #do something with $1
>> end
>
> Well, in this particular case, I am using the Fixnum returned, which is
> why I am making the assignment. I normally otherwise do as you say,
> using "if string =~ /regexp/".
Personally I prefer to use /rx/ =~ str over str =~ /rx/ - to me this
makes it clearer that the RX is the one that does the matching. Just
personal taste maybe but I think I also remember that that variant is a
tad faster.
Kind regards
robert