Skip to content

Commit

Permalink
Support calling IO#readlines with chomp keyword argument
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Mar 25, 2024
1 parent 54b0d72 commit 14f6b9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/polyphony/extensions/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def read(name, length = nil, offset = nil, opt = EMPTY_HASH)
end

alias_method :orig_readlines, :readlines
def readlines(name, sep = $/, limit = nil, getline_args = EMPTY_HASH)
def readlines(name, sep = $/, limit = nil, getline_args = EMPTY_HASH, chomp: false)
File.open(name, 'r') do |f|
f.readlines(sep, **getline_args)
f.readlines(sep, chomp: chomp, **getline_args)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/test_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,12 @@ def test_readlines
assert_equal "end\n", lines[-1]
end

def test_readlines_with_chomp
lines = IO.readlines(__FILE__, chomp: true)
assert_equal "# frozen_string_literal: true", lines[0]
assert_equal "end", lines[-1]
end

WRITE_DATA = "foo\nbar קוקו"

def test_write_class_method
Expand Down

0 comments on commit 14f6b9c

Please sign in to comment.