Actions
Feature #18640
opendefault empty string argument for `String#sub` and `String#sub!`, e.g. `"hello".sub("l")`
Status:
Open
Assignee:
-
Target version:
-
Description
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.
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?
Updated by nobu (Nobuyoshi Nakada) over 2 years ago
- Tracker changed from Bug to Feature
- ruby -v deleted (
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin21]) - Backport deleted (
2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN)
Actions
Like0
Like0