diff options
author | Kazuki Tsujimoto <kazuki@callcc.net> | 2019-11-08 11:37:07 +0900 |
---|---|---|
committer | Kazuki Tsujimoto <kazuki@callcc.net> | 2019-11-08 11:37:46 +0900 |
commit | d4da74ea786da7906fdb85e593593a9c6c11fe96 (patch) | |
tree | 98682735d82abf9c8d05bc5c718c00ee88d17248 /test/ruby/test_struct.rb | |
parent | 766115010932d977142097f60c76dd20af73196e (diff) | |
download | ruby-d4da74ea786da7906fdb85e593593a9c6c11fe96.tar.gz |
Define Struct#deconstruct_keys
Diffstat (limited to 'test/ruby/test_struct.rb')
-rw-r--r-- | test/ruby/test_struct.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 22a6ce8241..06a8a1bb92 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -431,6 +431,18 @@ module TestStruct } end + def test_deconstruct_keys + klass = @Struct.new(:a, :b) + o = klass.new(1, 2) + assert_equal({a: 1, b: 2}, o.deconstruct_keys(nil)) + assert_equal({a: 1, b: 2}, o.deconstruct_keys([:b, :a])) + assert_equal({a: 1}, o.deconstruct_keys([:a])) + assert_equal({}, o.deconstruct_keys([:a, :c])) + assert_raise(TypeError) { + o.deconstruct_keys(0) + } + end + class TopStruct < Test::Unit::TestCase include TestStruct |