Re: Possible Regexp documentation bug

"Konrad Meyer" <[email protected]> Sun, 15 Jul 2007 11:07:24 -0700
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
On 15/07/07, Chris Wilson <[email protected]> wrote:
> Hi all,
>
> I think I found a small bug in the description of the Regexp.escape method
> (http://www.ruby-doc.org/core/classes/Regexp.html#M001216).
>
> It says:
>
> "(Regexp.escape) Escapes any characters that would have special meaning in
> a regular expression. Returns a new escaped string, or self if no
> characters are escaped. For any string, Regexp.escape(str)=~str will be
> true."
>
> I think the last part is incorrect. The left-hand side of the =~ operator
> should be a string, the right-hand side should be a regexp. So if the
> escape method does change anything, the condition will not hold.
>
> I think it would be more accurate to say:
>
>    "str =~ Regexp.escape(str) will be true."
>
> Is that right? And how should one go about changing the documentation?
>
> Cheers, Chris.

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