[ruby-core:123722] [Ruby Feature#21653] Unify Hash methods and preserving default/default_proc
From:
"petrenkorf (Petris Fernandes) via ruby-core" <ruby-core@...>
Date:
2025-11-07 17:22:16 UTC
List:
ruby-core #123722
Issue #21653 has been updated by petrenkorf (Petris Fernandes).
I confirmed the behavior you described on version 3.2.4 while testing Hash#compact, but looks like it is already fixed on version 3.5.0dev (Although I did not checked the other methods you mentioned).
----------------------------------------
Feature #21653: Unify Hash methods and preserving default/default_proc
https://bugs.ruby-lang.org/issues/21653#change-115109
* Author: andrykonchin (Andrew Konchin)
* Status: Open
----------------------------------------
All the Hash methods that return a new instance of Hash don't preserve the `default` and `default_proc` properties except `#compact` and `#merge`:
```ruby
h = {a: 1}
h.default = 0
h.compact[:f] == 0 # => true
h.merge(b: 2)[:f] == 0 # => true
```
Propose to unify Hash methods select/slice/reject/except/compact/merge/transform_values/transform_keys/invert/to_h/Hash[] and to preserve or not preserve default/default_proc altogether.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/