From: Eric Wong Date: 2016-11-21T21:50:34+00:00 Subject: [ruby-core:78239] Re: [Ruby trunk Feature#12964] Add sub? and gsub? method to string class. lachlan@wilgerfamily.com wrote: > The sub? and gsub? method would allow you to check if you can > sub or gsub the string. We already added Regexp#match? for Ruby 2.4 to check this. Fwiw, I prefer to use bang methods if the substitution is likely; and maybe String#dup if the original needs to be preserved[*]. if foo.sub!(/^something /, '') ... end [*] Strings are copy-on-write in MRI, so at most you allocate one object and copy 40 bytes if no substitution is possible. Unsubscribe: