Download Firefox: WindowsMac OS X
logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: Possible Regexp documentation bug: msg#00002

Subject: Re: Possible Regexp documentation bug
On 15/07/07, Chris Wilson <chris@xxxxxxxxx> 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'.




<Prev in Thread] Current Thread [Next in Thread>