From 9c9db64d7e9058dc6fc7ead3791b259685798806 Mon Sep 17 00:00:00 2001 From: ktsj Date: Wed, 17 Apr 2019 06:48:05 +0000 Subject: [PATCH] Define Struct#deconstruct git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- struct.c | 2 ++ test/ruby/test_pattern_matching.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/struct.c b/struct.c index b85f7c035e..4ebf6aa3fa 100644 --- a/struct.c +++ b/struct.c @@ -1345,6 +1345,8 @@ InitVM_Struct(void) 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 diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index b0d8e4778b..9153297d39 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1072,4 +1072,16 @@ END 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