From 83ff0f74bf69650754cac020bcd4ff9adbba877e Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Thu, 24 Sep 2020 18:38:11 -0500 Subject: [PATCH] Enhanced RDoc for String#match? (#3576) * Enhanced RDoc for String#match? --- string.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/string.c b/string.c index fa14888d5c..e2c7bfbe05 100644 --- a/string.c +++ b/string.c @@ -3860,6 +3860,9 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str) * 'foo' =~ /o/ # => 1 * 'foo' =~ /x/ # => nil * + * Note: also updates + * {Regexp-related global variables}[Regexp.html#class-Regexp-label-Special+global+variables]. + * * If the given +object+ is not a \Regexp, returns the value * returned by object =~ self. * @@ -3898,6 +3901,9 @@ static VALUE get_pat(VALUE); * * Returns a \Matchdata object (or +nil+) based on +self+ and the given +pattern+. * + * Note: also updates + * {Regexp-related global variables}[Regexp.html#class-Regexp-label-Special+global+variables]. + * * - Computes +regexp+ by converting +pattern+ (if not already a \Regexp). * regexp = Regexp.new(pattern) * - Computes +matchdata+, which will be either a \MatchData object or +nil+ @@ -3937,19 +3943,25 @@ rb_str_match_m(int argc, VALUE *argv, VALUE str) /* * call-seq: - * str.match?(pattern) -> true or false - * str.match?(pattern, pos) -> true or false + * string.match?(pattern, offset = 0) -> true or false * - * Converts _pattern_ to a +Regexp+ (if it isn't already one), then - * returns a +true+ or +false+ indicates whether the regexp is - * matched _str_ or not without updating $~ and other - * related variables. If the second parameter is present, it - * specifies the position in the string to begin the search. + * Returns +true+ or +false+ based on whether a match is found for +self+ and +pattern+. * - * "Ruby".match?(/R.../) #=> true - * "Ruby".match?(/R.../, 1) #=> false - * "Ruby".match?(/P.../) #=> false - * $& #=> nil + * Note: does not update + * {Regexp-related global variables}[Regexp.html#class-Regexp-label-Special+global+variables]. + * + * Computes +regexp+ by converting +pattern+ (if not already a \Regexp). + * regexp = Regexp.new(pattern) + * + * Returns +true+ if self+.match(regexp) returns a \Matchdata object, + * +false+ otherwise: + * 'foo'.match?(/o/) # => true + * 'foo'.match?('o') # => true + * 'foo'.match?(/x/) # => false + * + * If \Integer argument +offset+ is given, the search begins at index +offset+: + * 'foo'.match?('f', 1) # => false + * 'foo'.match?('o', 1) # => true */ static VALUE