Actions
Bug #16660
closedStruct#deconstruct_keys inconsistent behavior
Description
Here is an example of a kind of surprising (at least to me) Struct#deconstruct_keys
behaviour:
klass = Struct.new(:a, :b)
s = klass.new(1, 2)
- When some keys are not recognized and the total number of the keys is not greater than the size of the struct:
s.deconstruct_keys([:a, :c])
#=> {a: 1}
- When some keys are not recognized but the total number of the keys is greater than the size of the struct:
s.deconstruct_keys([:a, :b, :c])
#=> {}
It's not clear why the first one filters unknown keys and the latter one returns an empty Hash instead of the {a: 1}
.
This behaviour was introduced in https://github.com/ruby/ruby/commit/2439948bcc0ec9daf91cf79301195e59bad49aff. Prior to that change an empty hash was returned in both cases.
Actions
Like0
Like0Like0Like0Like0