Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

String#tr!

(::String::selector source, ::string replacement) -> self?
tr!(selector, replacements) → self or nil
tr!(pairs) → self or nil

Like String#tr, except:

  • Performs substitutions in self (not in a copy of self).

  • Returns self if any modifications were made, nil otherwise.

Related: Modifying.

See also #tr #tr_s #to_sym #tr_s! also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0