[ruby-core:103070] [Ruby master Bug#17735] `Hash#transform_keys!` drops non evaluated keys
From:
nagachika00@...
Date:
2021-03-28 09:55:25 UTC
List:
ruby-core #103070
Issue #17735 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
I have confirmed that the issue is reproducible on 2.6/2.7 too.
----------------------------------------
Bug #17735: `Hash#transform_keys!` drops non evaluated keys
https://bugs.ruby-lang.org/issues/17735#change-91133
* Author: kachick (Kenichi Kamiya)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
* Backport: 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
----------------------------------------
```ruby
hash = {a: 1, b: 2, c: 3}
hash.transform_values!(){ raise } rescue
p hash #=> {:a=>1, :b=>2, :c=>3}
```
```ruby
hash = {a: 1, b: 2, c: 3}
hash.transform_keys!(){ raise } rescue
p hash #=> {}
```
Is this an intentional behavior?
I expected behavior like `transform_values!` in `transform_keys!` (Keeping non evaluated key-value pairs when exiting the block).
PR: https://github.com/ruby/ruby/pull/4294
--
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>