[#109207] [Ruby master Feature#18915] New error class: NotImplementedYetError or scope change for NotImplementedYet — Quintasan <noreply@...>
Issue #18915 has been reported by Quintasan (Michał Zając).
18 messages
2022/07/14
[ruby-core:109281] [Ruby master Bug#18768] Inconsistent behavior of IO, StringIO and String each_line methods when return paragraph and chomp: true passed
From:
"mame (Yusuke Endoh)" <noreply@...>
Date:
2022-07-21 12:25:23 UTC
List:
ruby-core #109281
Issue #18768 has been updated by mame (Yusuke Endoh).
We discussed this at the dev meeting, and @matz agreed with @jeremyevans0: `chomp: true` should remove the separator. Could you please merge the change?
----------------------------------------
Bug #18768: Inconsistent behavior of IO, StringIO and String each_line methods when return paragraph and chomp: true passed
https://bugs.ruby-lang.org/issues/18768#change-98413
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* ruby -v: 3.0.3
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
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("", chomp: true).to_a
#=> ["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.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>