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

ruby-changes:55378

From: ktsj <ko1@a...>
Date: Wed, 17 Apr 2019 15:48:10 +0900 (JST)
Subject: [ruby-changes:55378] ktsj:r67587 (trunk): Define Struct#deconstruct

ktsj	2019-04-17 15:48:05 +0900 (Wed, 17 Apr 2019)

  New Revision: 67587

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

  Log:
    Define Struct#deconstruct

  Modified files:
    trunk/struct.c
    trunk/test/ruby/test_pattern_matching.rb
Index: test/ruby/test_pattern_matching.rb
===================================================================
--- test/ruby/test_pattern_matching.rb	(revision 67586)
+++ test/ruby/test_pattern_matching.rb	(revision 67587)
@@ -1072,4 +1072,16 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pattern_matching.rb#L1072
       end
     end
   end
+
+  ################################################################
+
+  def test_struct
+    assert_block do
+      s = Struct.new(:a, :b)
+      case s[0, 1]
+      in 0, 1
+        true
+      end
+    end
+  end
 end
Index: struct.c
===================================================================
--- struct.c	(revision 67586)
+++ struct.c	(revision 67587)
@@ -1345,6 +1345,8 @@ InitVM_Struct(void) https://github.com/ruby/ruby/blob/trunk/struct.c#L1345
 
     rb_define_method(rb_cStruct, "members", rb_struct_members_m, 0);
     rb_define_method(rb_cStruct, "dig", rb_struct_dig, -1);
+
+    rb_define_method(rb_cStruct, "deconstruct", rb_struct_to_a, 0);
 }
 
 #undef rb_intern

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

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