From: "andrykonchin (Andrew Konchin)" Date: 2022-05-10T13:29:08+00:00 Subject: [ruby-core:108502] [Ruby master Bug#18770] Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true Issue #18770 has been reported by andrykonchin (Andrew Konchin). ---------------------------------------- Bug #18770: Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true https://bugs.ruby-lang.org/issues/18770 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal * ruby -v: 3.0.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- IO's and StringIO's `#each` method (and similar ones - `#gets`, `#readline` etc) behave in a different way in the following case: - separator is `nil` - limit is passed - `chomp: true` passed In this case `StringIO#each` removes trailing `\n` but `IO#each` does not: ```ruby StringIO.new("abc\n\ndef\n").each(nil, 2, chomp: true).to_a #=> ["ab", "c", "\nd", "ef", ""] File.open('chomp.txt').each(nil, 2, chomp: true).to_a #=> ["ab", "c\n", "\nd", "ef", "\n"] ``` The file has the same content: ```ruby File.read('chomp.txt'); #=> "abc\n\ndef\n" ``` Expected behavior - both methods return the same result. -- https://bugs.ruby-lang.org/ Unsubscribe: