Skip to content
instance method

String#sub!

(::Regexp | ::string pattern, ::string | ::hash[::String, ::_ToS] replacement) -> self?
(::Regexp | ::string pattern) { (::String match) -> ::_ToS } -> self?
sub!(pattern, replacement) → self or nil
sub!(pattern) {|match| ... } → self or nil

Like String#sub, except that:

  • Changes are made to self, not to copy of self.

  • Returns self if any changes are made, nil otherwise.

Related: see Modifying.

See also #sub #succ #strip! #succ! also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0