[#92070] [Ruby trunk Feature#15667] Introduce malloc_trim(0) in full gc cycles — sam.saffron@...
Issue #15667 has been updated by sam.saffron (Sam Saffron).
3 messages
2019/04/01
[ruby-core:92407] [Ruby trunk Feature#12698] Method to delete a substring by regex match
From:
svoop@...
Date:
2019-04-25 13:05:44 UTC
List:
ruby-core #92407
Issue #12698 has been updated by svoop (Sven Schwyn).
The suggestion by @knu is pretty cool if you think about it: Since both `sub` and `gsub` exist, the uncertainty whether only one or all occurrences are deleted is gone. Also, with this in place, `delete` could be deprecated IMO (and removed on Ruby 3 which will most likely break existing code in other places as well).
----------------------------------------
Feature #12698: Method to delete a substring by regex match
https://bugs.ruby-lang.org/issues/12698#change-77765
* Author: sawa (Tsuyoshi Sawada)
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
There is frequent need to delete a substring from a string. There already are methods `String#delete` and `String#delete!`, but their feature is a little bit different from the use cases that I am mentioning here.
I request methods that take a string or a regexp as an argument, and delete the matches from the receiver string. I am not sure of the method name, and I will use the term `remove` here. It can be named in some other better way. I request all combinations of global vs. local, and non-destructive vs. destructive. The expected feature is something like the following. First, the non-destructive ones:
```ruby
"abcabc".remove("c") # => "ababc"
"abcabc".remove(/\zc/) # => "abcab"
"abcabc".gremove("c") # => "abab"
"abcabc".gremove(/c/) # => "abab"
```
Then, the destructive ones:
```ruby
s = "abcabc"
s.remove!("c") # => "ababc"
s # => "ababc"
s = "abcabc"
s.gremove!("d") # => nil
s # => "abcabc"
```
Using this, cases like https://bugs.ruby-lang.org/issues/12694 would be just special cases. They can be handled like this:
```ruby
"abcdef".remove(/\Aabc/) # => "def"
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>