Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#gsub!

gsub!(pattern, replacement) → self or nil
gsub!(pattern) {|match| ... } → self or nil
gsub!(pattern) → an_enumerator

Performs the specified substring replacement(s) on self; returns self if any replacement occurred, nil otherwise.

See Substitution Methods.

Returns an Enumerator if no replacement and no block given.

Related: String#sub, String#gsub, String#sub!.

See also #gsub #hash #grapheme_clusters #hex also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0