Re: Possible Regexp documentation bug

Ryan Davis <[email protected]> Sun, 15 Jul 2007 11:01:35 -0700
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
On Jul 15, 2007, at 10:39 , Chris Wilson 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."

502 % ri Regexp.=~
No, it works either way:

-------------------------------------------------------------- Regexp#=~
      rxp.match(str)   => matchdata or nil
------------------------------------------------------------------------
      Returns a +MatchData+ object describing the match, or +nil+ if
      there was no match. This is equivalent to retrieving the value of
      the special variable +$~+ following a normal match.

         /(.)(.)(.)/.match("abc")[2]   #=> "b"

> Is that right? And how should one go about changing the documentation?

You'd check out the source for ruby via subversion, make and test the  
change, and thes submit the patch on the ruby project on  
rubyforge.org assigning the documentation category to it.