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

ruby-changes:30921

From: zzak <ko1@a...>
Date: Sat, 21 Sep 2013 00:51:34 +0900 (JST)
Subject: [ruby-changes:30921] zzak:r43000 (trunk): * enumerator.c: [DOC] Enumerator#each arguments documentation [GH-388]

zzak	2013-09-21 00:51:17 +0900 (Sat, 21 Sep 2013)

  New Revision: 43000

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

  Log:
    * enumerator.c: [DOC] Enumerator#each arguments documentation [GH-388]
      Patch by @kachick  https://github.com/ruby/ruby/pull/388

  Modified files:
    trunk/ChangeLog
    trunk/enumerator.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42999)
+++ ChangeLog	(revision 43000)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep 21 00:50:02 2013  Zachary Scott  <e@z...>
+
+	* enumerator.c: [DOC] Enumerator#each arguments documentation [GH-388]
+	  Patch by @kachick  https://github.com/ruby/ruby/pull/388
+
 Sat Sep 21 00:49:16 2013  Zachary Scott  <e@z...>
 
 	* enum.c: [DOC] Enumerable#to_a accepts arguments [GH-388]
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 42999)
+++ enumerator.c	(revision 43000)
@@ -434,10 +434,38 @@ enumerator_block_call(VALUE obj, rb_bloc https://github.com/ruby/ruby/blob/trunk/enumerator.c#L434
 
 /*
  * call-seq:
- *   enum.each {...}
+ *   enum.each { |elm| block }                    -> obj
+ *   enum.each                                    -> enum
+ *   enum.each(*appending_args) { |elm| block }   -> obj
+ *   enum.each(*appending_args)                   -> an_enumerator
  *
- * Iterates over the block according to how this Enumerable was constructed.
- * If no block is given, returns self.
+ * Iterates over the block according to how this Enumerator was constructed.
+ * If no block and no arguments are given, returns self.
+ *
+ * === Examples
+ *
+ *   "Hello, world!".scan(/\w+/)                     #=> ["Hello", "world"]
+ *   "Hello, world!".to_enum(:scan, /\w+/).to_a      #=> ["Hello", "world"]
+ *   "Hello, world!".to_enum(:scan).each(/\w+/).to_a #=> ["Hello", "world"]
+ *
+ *   obj = Object.new
+ *
+ *   def obj.each_arg(a, b=:b, *rest)
+ *     yield a
+ *     yield b
+ *     yield rest
+ *     :method_returned
+ *   end
+ *
+ *   enum = obj.to_enum :each_arg, :a, :x
+ *
+ *   enum.each.to_a                  #=> [:a, :x, []]
+ *   enum.each.equal?(enum)          #=> true
+ *   enum.each { |elm| elm }         #=> :method_returned
+ *
+ *   enum.each(:y, :z).to_a          #=> [:a, :x, [:y, :z]]
+ *   enum.each(:y, :z).equal?(enum)  #=> false
+ *   enum.each(:y, :z) { |elm| elm } #=> :method_returned
  *
  */
 static VALUE

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

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