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?
Actions
Like0
Like0