[DOC] String#sub! and String#gsub! return nil if no replacement occured

This commit is contained in:
Holger Just 2024-10-07 10:20:03 +02:00 committed by GitHub
parent 32c733f57b
commit 7081838d2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-10-07 08:20:21 +00:00
Merged: https://github.com/ruby/ruby/pull/11700

Merged-By: nobu <nobu@ruby-lang.org>
2 changed files with 6 additions and 4 deletions

View File

@ -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].
*

View File

@ -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:
#