[#66126] Creation/Conversion methods/functions table for Ruby types — SASADA Koichi <ko1@...>
Hi,
5 messages
2014/11/07
[#66248] [ruby-trunk - Feature #10423] [PATCH] opt_str_lit*: avoid literal string allocations — normalperson@...
Issue #10423 has been updated by Eric Wong.
3 messages
2014/11/13
[#66595] [ruby-trunk - Bug #10557] [Open] Block not given when the argument is a string — bartosz@...
Issue #10557 has been reported by Bartosz Kopinski.
3 messages
2014/11/30
[ruby-core:66392] [ruby-trunk - Bug #10534] Enumerator methods other than "next" do not respect "peek"
From:
ruby-core@...
Date:
2014-11-21 14:32:02 UTC
List:
ruby-core #66392
Issue #10534 has been updated by Marc-Andre Lafortune.
Assignee deleted (Yukihiro Matsumoto)
`next` and `peek` indeed live in their little world described as "external enumeration" in the documentation.
The documentation of `next` and `next_values` states:
* Note that +next_values+ does not affect other non-external enumeration
* methods unless underlying iteration method itself has side-effect, e.g.
* IO#each_line.
The doc of `peek` and `peek_values` would benefit from a similar note. Maybe we should turn it around in this case, like:
* Note that +peek+ will affect other non-external enumeration
* methods if underlying iteration method itself has side-effect, e.g.
* IO#each_line.
----------------------------------------
Bug #10534: Enumerator methods other than "next" do not respect "peek"
https://bugs.ruby-lang.org/issues/10534#change-50032
* Author: Jonas Nicklas
* Status: Open
* Priority: Normal
* Assignee:
* Category: core
* Target version:
* ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
It seems like using "peek" and then calling other methods on the Enumerator consumes the value that was peeked at. While `next` correctly returns the peeked-at value the next time it is called, other Enumerator methods such as `to_a` and `each` do not.
~~~
>> enum = StringIO.new("foo").each
=> #<Enumerator: #<StringIO:0x007ff3313d8688>:each>
>> enum.peek
=> "foo"
>> enum.to_a
=> []
~~~
Here the final call to `enum.to_a` should have returned `["foo"]`, since we have not consumed anything from the enumerator yet. The peeked-at value is not included in the returned Array.
Taking a glance at the code, it seems that these methods do not call `next` under the hood, but instead have some other mechanism of iterating over the Enumerator, this seems very counter-intuitive to me.
--
https://bugs.ruby-lang.org/