Re: Possible Regexp documentation bug

"Konrad Meyer" <[email protected]> Sun, 15 Jul 2007 11:46:58 -0700
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
On 15/07/07, Chris Wilson <[email protected]> wrote:
> 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?

Yes, I was wrong the first go around :D.

> > 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.

Either way works. Probably best to be consistent in your own usage,
but that's about it.

> > 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.