summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolger Just <[email protected]>2024-10-07 10:20:03 +0200
committerGitHub <[email protected]>2024-10-07 17:20:03 +0900
commit7081838d2a6b64308161e46296dec5dcea01f789 (patch)
tree5f4422d95d105da5b96cabf47ffa3886e0ffc91f
parent32c733f57bb91e22972319ee63eac9521d954ebc (diff)
[DOC] String#sub! and String#gsub! return nil if no replacement occured
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11700 Merged-By: nobu <[email protected]>
-rw-r--r--string.c4
-rw-r--r--string.rb6
2 files changed, 6 insertions, 4 deletions
diff --git a/string.c b/string.c
index 0b3878b9b1..e193539f4f 100644
--- a/string.c
+++ b/string.c
@@ -6092,8 +6092,8 @@ rb_pat_search(VALUE pat, VALUE str, long pos, int set_backref_str)
* sub!(pattern, replacement) -> self or nil
* sub!(pattern) {|match| ... } -> self or nil
*
- * Returns +self+ with only the first occurrence
- * (not all occurrences) of the given +pattern+ replaced.
+ * Replaces the first occurrence (not all occurrences) of the given +pattern+
+ * on +self+; returns +self+ if a replacement occurred, +nil+ otherwise.
*
* See {Substitution Methods}[rdoc-ref:String@Substitution+Methods].
*
diff --git a/string.rb b/string.rb
index 1f0e9ceace..941fda0c24 100644
--- a/string.rb
+++ b/string.rb
@@ -29,9 +29,11 @@
# These methods perform substitutions:
#
# - String#sub: One substitution (or none); returns a new string.
-# - String#sub!: One substitution (or none); returns +self+.
+# - String#sub!: One substitution (or none); returns +self+ if any changes,
+# +nil+ otherwise.
# - String#gsub: Zero or more substitutions; returns a new string.
-# - String#gsub!: Zero or more substitutions; returns +self+.
+# - String#gsub!: Zero or more substitutions; returns +self+ if any changes,
+# +nil+ otherwise.
#
# Each of these methods takes:
#