Project

General

Profile

Actions

Bug #17735

closed

`Hash#transform_keys!` drops non evaluated keys

Added by kachick (Kenichi Kamiya) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
[ruby-core:102949]

Description

hash = {a: 1, b: 2, c: 3}
hash.transform_values!(){ raise } rescue
p hash #=> {:a=>1, :b=>2, :c=>3}
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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0