[ruby-core:77021] [Ruby trunk Feature#12694] Want a String method to remove heading substr
From:
sonots@...
Date:
2016-08-23 12:01:43 UTC
List:
ruby-core #77021
Issue #12694 has been updated by Naotoshi Seo.
Thanks, I found an issue which is 3 years old https://bugs.ruby-lang.org/issues/6842
----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60248
* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
I often write codes like:
```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```
I want a short hand which is something like:
```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```
Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>