diff --git a/lib/polyphony/extensions/io.rb b/lib/polyphony/extensions/io.rb index dbf315fb..f6a67e32 100644 --- a/lib/polyphony/extensions/io.rb +++ b/lib/polyphony/extensions/io.rb @@ -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 diff --git a/test/test_io.rb b/test/test_io.rb index 5b22471f..a7d7b730 100644 --- a/test/test_io.rb +++ b/test/test_io.rb @@ -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