Project

General

Profile

Actions

Feature #21653

open

Unify Hash methods and preserving default/default_proc

Feature #21653: Unify Hash methods and preserving default/default_proc

Added by andrykonchin (Andrew Konchin) 21 days ago. Updated 12 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:123575]

Description

All the Hash methods that return a new instance of Hash don't preserve the default and default_proc properties except #compact and #merge:

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.

Updated by petrenkorf (Petris Fernandes) 12 days ago Actions #1 [ruby-core:123722]

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).

Updated by petrenkorf (Petris Fernandes) 12 days ago Actions #2 [ruby-core:123723]

I just confirmed the behavior described on version 3.5.0dev, but for Hash#select. I'll check other methods to see which of them are not preserving default and default_proc

Actions

Also available in: PDF Atom