Project

General

Profile

Feature #12694

Updated by sonots (Naotoshi Seo) over 7 years ago

I often write codes like: 

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

 I want a short hand which is something like: 

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

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

Back