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

Add chomp option to IO.readlines #780

Merged
merged 1 commit into from
Sep 7, 2021
Merged

Add chomp option to IO.readlines #780

merged 1 commit into from
Sep 7, 2021

Conversation

ybiquitous
Copy link
Contributor

@ybiquitous ybiquitous commented Sep 7, 2021

This PR adds the chomp option of the IO.readlines method signature.

$ irb
irb(main):001:0> IO.write 'foo.txt', [1, 2, 3].join("\n")
=> 5
irb(main):002:0> IO.readlines 'foo.txt'
=> ["1\n", "2\n", "3"]
irb(main):003:0> IO.readlines 'foo.txt', chomp: true
=> ["1", "2", "3"]
irb(main):004:0> IO.readlines 'foo.txt', chomp: false
=> ["1\n", "2\n", "3"]
irb(main):005:0> IO.readlines 'foo.txt', chomp: nil
=> ["1\n", "2\n", "3"]

See also https://ruby-doc.org/core-3.0.2/IO.html#readlines-method

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@soutaro soutaro merged commit f41fddb into ruby:master Sep 7, 2021
@ybiquitous ybiquitous deleted the io-readlines branch September 7, 2021 14:07
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