From f74021e12ba3b067934271ab193ed8dc694ceb04 Mon Sep 17 00:00:00 2001 From: Marcus Stollsteimer Date: Wed, 8 Jan 2020 20:47:10 +0100 Subject: [PATCH] Improve docs for String#=~ Move existing example to the corresponding paragraph and add an example for `string =~ regexp` vs. `regexp =~ string`; avoid using the receiver's identifier from the call-seq because it does not appear in rendered HTML docs; mention deprecation of Object#=~; fix some markup and typos. --- string.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/string.c b/string.c index c9383937ae..af02cdde51 100644 --- a/string.c +++ b/string.c @@ -3785,18 +3785,23 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str) * call-seq: * str =~ obj -> integer or nil * - * Match---If obj is a Regexp, use it as a pattern to match - * against str,and returns the position the match starts, or - * nil if there is no match. Otherwise, invokes - * obj.=~, passing str as an argument. The default - * =~ in Object returns nil. - * - * Note: str =~ regexp is not the same as - * regexp =~ str. Strings captured from named capture groups - * are assigned to local variables only in the second case. + * Match---If obj is a Regexp, uses it as a pattern to match + * against the receiver, and returns the position the match starts, + * or +nil+ if there is no match. Otherwise, invokes obj.=~, + * passing the string as an argument. + * The default Object#=~ (deprecated) returns +nil+. * * "cat o' 9 tails" =~ /\d/ #=> 7 * "cat o' 9 tails" =~ 9 #=> nil + * + * Note that string =~ regexp is not the same as + * regexp =~ string. Strings captured from named capture groups + * are assigned to local variables only in the second case. + * + * "no. 9" =~ /(?\d+)/ + * number #=> nil (not assigned) + * /(?\d+)/ =~ "no. 9" + * number #=> "9" */ static VALUE