mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
Define Struct#deconstruct_keys
This commit is contained in:
parent
7661150109
commit
d4da74ea78
3 changed files with 64 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue