Hi Konrad,
On Sun, 15 Jul 2007, Konrad Meyer wrote:
> While =~ is not an operator, it is a method of String and Regexp
> instances, Regexp.escape (from quick irb testing) returns a string.
> And String#=~ expects a Regexp instance, not a string. So I think it
> would be correct to change that to something like `Regexp.escape(str)
> =~ Regexp.new(str) will be true'.
I didn't spot this when replying to your previous message, but I believe
that it's still incorrect, because it treats the unescaped str as a valid
regexp (on the right) and compares it with the escaped form (on the left)
as though that were the original string.
I guess that str =~ Regexp.new(Regexp.escape(str)) is correct?
I think the bit after the `and' is excessive. It's not the job of this
method's documentation to clarify that str =~ rxp is the same as rxp =~
str.
OK, then which is the preferred form in Ruby? I'm more accustomed to the
Perl form, where str =~ rxp.
Er, and also the changelog entry for documentation is probably a
little excessive.
Sorry, I'm new here, I was just following the advice on the website. I'll
remove it.
Cheers, Chris.
--
_____ __ _
\ __/ / ,__(_)_ | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |
|