Project

General

Profile

Feature #10574

Add String#lchomp and String.lchomp!

Added by javawizard (Alex Boyd) about 5 years ago. Updated almost 5 years ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:66727]

Description

With the expected behavior, i.e.

irb(main):013:0> 'foobar'.lchomp('foo')
=> "bar"
irb(main):014:0> 'foobar'.lchomp('baz')
=> "foobar"

A quick google search will turn up plenty of practical uses for this, as well as lots of libraries that patch String themselves to add this.

History

Updated by shevegen (Robert A. Heiler) almost 5 years ago

Possibly also add the default without arguments in order to compare to .chomp:

"\nacbdef\n".chomp  # => "\nacbdef"
"\nacbdef\n".lchomp # => "acbdef\n"

Updated by javawizard (Alex Boyd) almost 5 years ago

Agreed. I was slightly lazy writing up my example... :-)

Also available in: Atom PDF