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

Readable prefix/suffix removal in Parser#strip_value #251

Merged
merged 2 commits into from
Jun 29, 2022
Merged

Readable prefix/suffix removal in Parser#strip_value #251

merged 2 commits into from
Jun 29, 2022

Conversation

Maumagnaguagno
Copy link
Contributor

The use of String#delete_prefix!/delete_suffix! makes this method more readable.
It also makes possible to strip strings with more than one character.

Note that I am using the methods ending with ! to modify value, this matches the already used strip!.
I also modified the early return to show that value is always returned, and with this PR all value modifications happen in-place.
This could be used to further simplify the method itself (no need to return a value) and the single usage I have found in Parser#parse_no_quote: line = strip_value(line) to strip_value(line).

I have not done this modification yet to leave it open for discussion.

The use of String#delete_prefix!/delete_suffix! makes this method more readable.
lib/csv/parser.rb Outdated Show resolved Hide resolved
lib/csv/parser.rb Outdated Show resolved Hide resolved
@kou kou merged commit 698d1fa into ruby:master Jun 29, 2022
@kou
Copy link
Member

kou commented Jun 29, 2022

Thanks!

@Maumagnaguagno Maumagnaguagno deleted the refactor-strip-value branch June 29, 2022 04:20
peterzhu2118 pushed a commit to Shopify/ruby that referenced this pull request Dec 6, 2022
(ruby/csv#251)

The use of String#delete_prefix!/delete_suffix! makes this method more readable.

ruby/csv@698d1fad55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants