From: dorianmariefr Date: 2022-03-17T14:46:35+00:00 Subject: [ruby-core:107955] [Ruby master Bug#18640] default empty string argument for `String#sub` and `String#sub!`, e.g. `"hello".sub("l")` Issue #18640 has been reported by dorianmariefr (Dorian Mari��). ---------------------------------------- Bug #18640: default empty string argument for `String#sub` and `String#sub!`, e.g. `"hello".sub("l")` https://bugs.ruby-lang.org/issues/18640 * Author: dorianmariefr (Dorian Mari��) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin21] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- Most of the time I replace a string with an empty string. And I think that's the main use case. Also, `String#delete` deletes every character provided when passed a string. ```ruby class String alias original_sub sub alias original_sub! sub! def sub(pattern, replacement = "", &block) original_sub(pattern, replacement, &block) end def sub!(pattern, replacement = "", &block) original_sub!(pattern, replacement, &block) end end puts "hello".sub("l") puts "hello".sub!("l") ``` What do you think? -- https://bugs.ruby-lang.org/ Unsubscribe: