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

ruby-changes:25664

From: nobu <ko1@a...>
Date: Mon, 19 Nov 2012 16:31:24 +0900 (JST)
Subject: [ruby-changes:25664] nobu:r37721 (trunk): struct.c: yield assoc in each_pair

nobu	2012-11-19 16:31:05 +0900 (Mon, 19 Nov 2012)

  New Revision: 37721

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

  Log:
    struct.c: yield assoc in each_pair
    
    * struct.c (rb_struct_each_pair): yield associated pairs so that
      an unsplat argument can get both, for consistency with Hash,
      OpenStruct, and etc.  [ruby-dev:46533] [Bug #7382]

  Modified files:
    trunk/ChangeLog
    trunk/struct.c
    trunk/test/ruby/test_struct.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37720)
+++ ChangeLog	(revision 37721)
@@ -1,3 +1,9 @@
+Mon Nov 19 16:30:59 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* struct.c (rb_struct_each_pair): yield associated pairs so that
+	  an unsplat argument can get both, for consistency with Hash,
+	  OpenStruct, and etc.  [ruby-dev:46533] [Bug #7382]
+
 Mon Nov 19 16:17:53 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (LIBS): libelf is need on only FreeBSD.
Index: struct.c
===================================================================
--- struct.c	(revision 37720)
+++ struct.c	(revision 37721)
@@ -495,7 +495,9 @@
     RETURN_SIZED_ENUMERATOR(s, 0, 0, rb_struct_size);
     members = rb_struct_members(s);
     for (i=0; i<RSTRUCT_LEN(s); i++) {
-	rb_yield_values(2, rb_ary_entry(members, i), RSTRUCT_PTR(s)[i]);
+	VALUE key = rb_ary_entry(members, i);
+	VALUE value = RSTRUCT_PTR(s)[i];
+	rb_yield(rb_assoc_new(key, vlaue));
     }
     return s;
 }
Index: test/ruby/test_struct.rb
===================================================================
--- test/ruby/test_struct.rb	(revision 37720)
+++ test/ruby/test_struct.rb	(revision 37721)
@@ -1,3 +1,4 @@
+# -*- coding: us-ascii -*-
 require 'test/unit'
 require 'timeout'
 require_relative 'envutil'
@@ -117,6 +118,10 @@
     klass = Struct.new(:a, :b)
     o = klass.new(1, 2)
     assert_equal([[:a, 1], [:b, 2]], o.each_pair.to_a)
+    bug7382 = '[ruby-dev:46533]'
+    a = []
+    o.each_pair {|x| a << x}
+    assert_equal([[:a, 1], [:b, 2]], a, bug7382)
   end
 
   def test_inspect

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

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