Project

General

Profile

Actions

Bug #18770

closed

Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true

Added by andrykonchin (Andrew Konchin) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:108502]

Description

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:

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:

File.read('chomp.txt');
#=> "abc\n\ndef\n"

Expected behavior - both methods return the same result.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18768: Inconsistent behavior of IO, StringIO and String each_line methods when return paragraph and chomp: true passedClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0