[#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:109282] [Ruby master Bug#18770] Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: true
From:
"mame (Yusuke Endoh)" <noreply@...>
Date:
2022-07-21 12:26:23 UTC
List:
ruby-core #109282
Issue #18770 has been updated by mame (Yusuke Endoh).
We discussed this at the dev meeting, and @matz agreed with @jeremyevans0.
----------------------------------------
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#change-98414
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>