[前][次][番号順一覧][スレッド一覧]

ruby-changes:28831

From: akr <ko1@a...>
Date: Tue, 21 May 2013 22:54:41 +0900 (JST)
Subject: [ruby-changes:28831] akr:r40883 (trunk): Update doc.

akr	2013-05-21 22:54:31 +0900 (Tue, 21 May 2013)

  New Revision: 40883

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40883

  Log:
    Update doc.

  Modified files:
    trunk/enumerator.c

Index: enumerator.c
===================================================================
--- enumerator.c	(revision 40882)
+++ enumerator.c	(revision 40883)
@@ -819,6 +819,24 @@ enumerator_peek(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L819
  *
  * This value is cleared after being yielded.
  *
+ *   # Array#map passes the array's elements to "yield" and collects the
+ *   # results of "yield" as an array.
+ *   # Following example shows that "next" returns the passed elements and
+ *   # values passed to "feed" are collected as an array which can be
+ *   # obtained by StopIteration#result.
+ *   e = [1,2,3].map
+ *   p e.next           #=> 1
+ *   e.feed "a"
+ *   p e.next           #=> 2
+ *   e.feed "b"
+ *   p e.next           #=> 3
+ *   e.feed "c"
+ *   begin
+ *     e.next
+ *   rescue StopIteration
+ *     p $!.result      #=> ["a", "b", "c"]
+ *   end
+ *
  *   o = Object.new
  *   def o.each
  *     x = yield         # (2) blocks

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]