1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Improve documentation for Enumerator#next, next_values, peek and peek_values.

[DOC] [#16829]
This commit is contained in:
Marc-Andre Lafortune 2020-05-05 17:02:59 -04:00
parent 77f19d26b9
commit 7bde98125e

View file

@ -81,6 +81,14 @@
* puts e.next # => 3 * puts e.next # => 3
* puts e.next # raises StopIteration * puts e.next # raises StopIteration
* *
* Note that enumeration sequence by +next+, +next_values+, +peek+ and
* +peek_values+ do not affect other non-external
* enumeration methods, unless the underlying iteration method itself has
* side-effect, e.g. IO#each_line.
*
* Moreover, implementation typically uses fibers so performance could be
* slower and exception stacktraces different than expected.
*
* You can use this to implement an internal iterator as follows: * You can use this to implement an internal iterator as follows:
* *
* def ext_each(e) * def ext_each(e)
@ -804,6 +812,8 @@ get_next_values(VALUE obj, struct enumerator *e)
* internal position forward. When the position reached at the end, * internal position forward. When the position reached at the end,
* StopIteration is raised. * StopIteration is raised.
* *
* See class-level notes about external iterators.
*
* This method can be used to distinguish <code>yield</code> and <code>yield * This method can be used to distinguish <code>yield</code> and <code>yield
* nil</code>. * nil</code>.
* *
@ -837,10 +847,6 @@ get_next_values(VALUE obj, struct enumerator *e)
* # yield nil [nil] nil * # yield nil [nil] nil
* # yield [1, 2] [[1, 2]] [1, 2] * # yield [1, 2] [[1, 2]] [1, 2]
* *
* 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.
*
*/ */
static VALUE static VALUE
@ -894,9 +900,7 @@ ary2sv(VALUE args, int dup)
* p e.next #=> 3 * p e.next #=> 3
* p e.next #raises StopIteration * p e.next #raises StopIteration
* *
* Note that enumeration sequence by +next+ does not affect other non-external * See class-level notes about external iterators.
* enumeration methods, unless the underlying iteration methods itself has
* side-effect, e.g. IO#each_line.
* *
*/ */
@ -926,6 +930,8 @@ enumerator_peek_values(VALUE obj)
* doesn't move the internal position forward. If the position is already at * doesn't move the internal position forward. If the position is already at
* the end, StopIteration is raised. * the end, StopIteration is raised.
* *
* See class-level notes about external iterators.
*
* === Example * === Example
* *
* o = Object.new * o = Object.new
@ -960,6 +966,8 @@ enumerator_peek_values_m(VALUE obj)
* position forward. If the position is already at the end, StopIteration * position forward. If the position is already at the end, StopIteration
* is raised. * is raised.
* *
* See class-level notes about external iterators.
*
* === Example * === Example
* *
* a = [1,2,3] * a = [1,2,3]