[#97678] [Ruby master Feature#16752] :private param for const_set — bughitgithub@...
Issue #16752 has been reported by bughit (bug hit).
5 messages
2020/04/02
[ruby-core:97772] [Ruby master Bug#16660] Struct#deconstruct_keys inconsistent behavior
From:
matz@...
Date:
2020-04-10 05:31:45 UTC
List:
ruby-core #97772
Issue #16660 has been updated by matz (Yukihiro Matsumoto).
I agree that it's inconsistent and (a little bit) confusing. But it's not a bug.
I wish @ktsj to revisit this issue, but I honor his decision.
Matz.
----------------------------------------
Bug #16660: Struct#deconstruct_keys inconsistent behavior
https://bugs.ruby-lang.org/issues/16660#change-84986
* Author: palkan (Vladimir Dementyev)
* Status: Open
* Priority: Normal
* Assignee: ktsj (Kazuki Tsujimoto)
* ruby -v: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Here is an example of a kind of surprising (at least to me) `Struct#deconstruct_keys` behaviour:
```ruby
klass = Struct.new(:a, :b)
s = klass.new(1, 2)
```
1) When some keys are not recognized and the total number of the keys is not greater than the size of the struct:
```ruby
s.deconstruct_keys([:a, :c])
#=> {a: 1}
```
2) When some keys are not recognized but the total number of the keys is greater than the size of the struct:
```ruby
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.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>