Project

General

Profile

Bug #18768

Updated by andrykonchin (Andrew Konchin) almost 2 years ago

In IO, StringIO and String methods that return lines (e.g. `each`, `each_line`, `gets`, `readline`, `readlines`) behave in a different way when the following parameters are passed 
 - separator is `""` and 
 - `chomp` is `true`. 

 They truncate the new line characters between paragraphs and the trailing one differently: 

 ```ruby 
 "a\n\nb\n\nc\n".each_line("", chomp: true).to_a 
 #=> ["a\n", "b\n", "c\n"] 

 StringIO.new("a\n\nb\n\nc\n").each_line("", chomp: true).to_a 
 #=> ["a\n", "b\n", "c"] 

 File.open('chomp.txt').each_line("", IO.readlines('chomp.txt', "", chomp: true).to_a true) 
 #=> ["a", "b", "c\n"] 
 ``` 

 The text file content is the same: 

 ```ruby 
 File.read('chomp.txt') 
 #=> "a\n\nb\n\nc\n" 
 ``` 

 Expected behavior - they return the same result.

Back