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

ruby-changes:39445

From: hsbt <ko1@a...>
Date: Tue, 11 Aug 2015 10:48:26 +0900 (JST)
Subject: [ruby-changes:39445] hsbt:r51526 (trunk): * enum.c: added doc for Enumerable#zip

hsbt	2015-08-11 10:48:20 +0900 (Tue, 11 Aug 2015)

  New Revision: 51526

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

  Log:
    * enum.c: added doc for Enumerable#zip
      [fix GH-985] Patch by @yui-knk
    * test/ruby/test_enum.rb: added tests for Enumerable#zip
      [fix GH-985] Patch @yui-knk

  Modified files:
    trunk/ChangeLog
    trunk/enum.c
    trunk/test/ruby/test_enum.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51525)
+++ ChangeLog	(revision 51526)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Aug 11 10:48:16 2015  SHIBATA Hiroshi  <hsbt@r...>
+
+	* enum.c: added doc for Enumerable#zip
+	  [fix GH-985] Patch by @yui-knk
+	* test/ruby/test_enum.rb: added tests for Enumerable#zip
+	  [fix GH-985] Patch @yui-knk
+
 Tue Aug 11 10:33:26 2015  SHIBATA Hiroshi  <hsbt@r...>
 
 	* vm_method.c: typo fix [fix GH-993][ci skip] Patch by @0x0dea
Index: enum.c
===================================================================
--- enum.c	(revision 51525)
+++ enum.c	(revision 51526)
@@ -2454,6 +2454,10 @@ zip_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, me https://github.com/ruby/ruby/blob/trunk/enum.c#L2454
  *     [1, 2].zip(a, b)         #=> [[1, 4, 7], [2, 5, 8]]
  *     a.zip([1, 2], [8])       #=> [[4, 1, 8], [5, 2, nil], [6, nil, nil]]
  *
+ *     c = []
+ *     a.zip(b) { |x, y| c << x + y }  #=> nil
+ *     c                               #=> [11, 13, 15]
+ *
  */
 
 static VALUE
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 51525)
+++ test/ruby/test_enum.rb	(revision 51526)
@@ -434,8 +434,11 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L434
 
   def test_zip
     assert_equal([[1,1],[2,2],[3,3],[1,1],[2,2]], @obj.zip(@obj))
+    assert_equal([["a",1],["b",2],["c",3]], ["a", "b", "c"].zip(@obj))
+
     a = []
-    @obj.zip([:a, :b, :c]) {|x,y| a << [x, y] }
+    result = @obj.zip([:a, :b, :c]) {|x,y| a << [x, y] }
+    assert_nil result
     assert_equal([[1,:a],[2,:b],[3,:c],[1,nil],[2,nil]], a)
 
     a = []

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

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