instance method
compact
Ruby on Rails 5.2.8.1
Since v4.1.16 Last seen in v5.2.8.1Signature
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
# File activesupport/lib/active_support/core_ext/hash/compact.rb, line 12
def compact
select { |_, value| !value.nil? }
end
Defined in activesupport/lib/active_support/core_ext/hash/compact.rb line 12
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash