Actions
Bug #18770
closedInconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true
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.
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0