[DOC] Tweaks for String#=~ (#13325)

This commit is contained in:
Burdette Lamar 2025-05-15 10:18:49 -05:00 committed by GitHub
parent c3eb406876
commit 4fc5047af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-05-15 15:19:03 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>

View File

@ -5332,30 +5332,33 @@ rb_str_byterindex_m(int argc, VALUE *argv, VALUE str)
/*
* call-seq:
* string =~ regexp -> integer or nil
* string =~ object -> integer or nil
* self =~ object -> integer or nil
*
* Returns the Integer index of the first substring that matches
* the given +regexp+, or +nil+ if no match found:
* When +object+ is a Regexp, returns the index of the first substring in +self+
* matched by +object+,
* or +nil+ if no match is found;
* updates {Regexp-related global variables}[rdoc-ref:Regexp@Global+Variables]:
*
* 'foo' =~ /f/ # => 0
* $~ # => #<MatchData "f">
* 'foo' =~ /o/ # => 1
* $~ # => #<MatchData "o">
* 'foo' =~ /x/ # => nil
*
* Note: also updates Regexp@Global+Variables.
*
* If the given +object+ is not a Regexp, returns the value
* returned by <tt>object =~ self</tt>.
* $~ # => nil
*
* Note that <tt>string =~ regexp</tt> is different from <tt>regexp =~ string</tt>
* (see Regexp#=~):
*
* number= nil
* "no. 9" =~ /(?<number>\d+)/
* number # => nil (not assigned)
* /(?<number>\d+)/ =~ "no. 9"
* number #=> "9"
* number = nil
* 'no. 9' =~ /(?<number>\d+)/ # => 4
* number # => nil # Not assigned.
* /(?<number>\d+)/ =~ 'no. 9' # => 4
* number # => "9" # Assigned.
*
* If +object+ is not a Regexp, returns the value
* returned by <tt>object =~ self</tt>.
*
* Related: see {Querying}[rdoc-ref:String@Querying].
*/
static VALUE