Skip to content
instance method

Hash#compact

() -> ::Hash[K, V]
compact → new_hash

Returns a copy of self with all nil-valued entries removed:

Example
h = {foo: 0, bar: nil, baz: 2, bat: nil}
h.compact # => {foo: 0, baz: 2}

Related: see Methods for Deleting.

See also #compact! #clear #assoc #compare_by_identity also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0