Project

General

Profile

Actions

Feature #11818

closed

`Hash#compact`

Added by sawa (Tsuyoshi Sawada) over 8 years ago. Updated over 7 years ago.

Status:
Closed
Target version:
-
[ruby-core:72133]

Description

I request Hash#compact and Hash#compact! that remove the key-value pairs whose value is nil, as follows:

h1 = {a:, 1, b: nil, c: 2}
h1.compact # => {a: 1, c: 2}
h1 # => {a: 1, b: nil, c: 2}

h2 = {a:, 1, b: nil, c: 2}
h2.compact! # => {a: 1, c: 2}
h2 # => {a: 1, c: 2}

h3 = {a:, 1, c: 2}
h3.compact! # => nil
h3 # => {a: 1, c: 2}

I believe people have frequent need to do this.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0