Hash#compact
Returns a hash with non
nil
values.hash = { a: true, b: false, c: nil } hash.compact # => { a: true, b: false } hash # => { a: true, b: false, c: nil } { c: nil }.compact # => {} { c: true }.compact # => { c: true }
Source: Hash
A little like Array#compact
. Handy!