Project

General

Profile

Actions

Bug #12863

closed

Hash#compact! behavior different from the Active Support Hash#compact!

Added by cha1tanya (Prathamesh Sonpatki) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:77709]

Description

Hash#compact and Hash#compact! were added in https://bugs.ruby-lang.org/issues/11818 but the Hash#compact! is different from Active Support. Please check following snippet:

# Active Support
>> hash = { a: true, b: false, c: nil }
=> {:a=>true, :b=>false, :c=>nil}
>> hash.compact!
=> {:a=>true, :b=>false}
>> hash.compact!
=> nil

# Ruby dev

>> hash = { a: true, b: false, c: nil }
=> {:a=>true, :b=>false, :c=>nil}
>> hash.compact!
=> {:a=>true, :b=>false}
>> hash.compact!
=> {:a=>true, :b=>false}
>> 

@nobu (Nobuyoshi Nakada) Was it intentional to not return nil in case of compact! when none of the values are nil?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0