ruby-core

Mailing list archive

[#81492] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — normalperson@...

Issue #13618 has been reported by normalperson (Eric Wong).

12 messages 2017/06/01

[ruby-core:81699] [Ruby trunk Feature#12694] Want a String method to remove heading substr

From: matz@...
Date: 2017-06-16 06:11:30 UTC
List: ruby-core #81699
Issue #12694 has been updated by matz (Yukihiro Matsumoto).


I'd pick the name `delete_prefix`.

Matz.


----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65389

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/\A#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next