Re: Possible Regexp documentation bug

Chris Wilson <[email protected]> Sun, 15 Jul 2007 19:19:51 +0100 (BST)
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
On Sun, 15 Jul 2007, Konrad Meyer wrote:

>>  "(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 it would be more accurate to say:
>>
>>     "str =~ Regexp.escape(str) will be true."
...
> 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'.

Thanks Konrad and Ryan. Is the attached patch acceptable, documenting both 
forms in what I believe is the correct way?

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 |
ruby-regexp.patch (text/plain, 1.1 KB)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 12802)
+++ ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+Sun Jul 15 19:16:00 2007  Chris Wilson <[email protected]>
+
+	* re.c (rb_reg_s_quote): fix Regexp.escape documentation.
+
 Mon Jul 16 00:26:10 2007  Nobuyoshi Nakada  <[email protected]>
 
 	* bignum.c (rb_big_pow): removed invariant variable.  [ruby-dev:31236]
Index: re.c
===================================================================
--- re.c	(revision 12802)
+++ re.c	(working copy)
@@ -1944,7 +1944,9 @@
  *  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,
- *  <code>Regexp.escape(<i>str</i>)=~<i>str</i></code> will be true.
+ *  <code>Regexp.new(Regexp.escape(<i>str</i>)) =~ <i>str</i></code> and
+ *  <code><i>str</i> =~ Regexp.new(Regexp.escape(<i>str</i>))</code>
+ *  will be true.
  *
  *     Regexp.escape('\\*?{}.')   #=> \\\\\*\?\{\}\.
  */