Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement String#lchomp #3701

Merged
merged 1 commit into from Dec 15, 2016
Merged

Implement String#lchomp #3701

merged 1 commit into from Dec 15, 2016

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Dec 15, 2016

This PR adds String#lchomp method which removes given String | Char from the beginning of the string.

It's quite handy method, many times requested to be included in Ruby's stdlib.
See for instance https://www.reddit.com/r/ruby/comments/19khox/cmon_ruby_we_need_stringlchomp/

Other solutions to this issue are way less optimal:

  • "hello".reverse.chomp("hel".reverse).reverse
  • "hello".starts_with?("hel") ? "hello"["hel".size..-1] : "hello"
  • "hello".sub(/\Ahel/, "")

@asterite
Copy link
Member

I like it, thank you! I think it's symmetry with chomp makes it a good thing to have in the standard library.

@asterite asterite added this to the 0.20.2 milestone Dec 15, 2016
@asterite asterite merged commit 60bf3cd into crystal-lang:master Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants