Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

String#gsub!

(::Regexp | ::string pattern, ::string | ::hash[::String, ::_ToS] replacement) -> self?
(::Regexp | ::string pattern) -> ::Enumerator[::String, self?]
(::Regexp | ::string pattern) { (::String match) -> ::_ToS } -> self?
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.3 · 3.2 · 3.1 · 3.0