Module: Corefines::Hash::Compact
- Defined in:
- lib/corefines/hash.rb
Instance Method Summary collapse
-
#compact ⇒ Hash
A new hash with no key-value pairs which value is
nil. -
#compact! ⇒ Hash
Removes all key-value pairs from the hash which value is
nil.
Instance Method Details
#compact ⇒ Hash
Returns a new hash with no key-value pairs which value is nil.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/corefines/hash.rb', line 22 module Compact refine ::Hash do def compact reject { |_, value| value.nil? } end def compact! delete_if { |_, value| value.nil? } end end end |
#compact! ⇒ Hash
Removes all key-value pairs from the hash which value is nil.
Same as #compact, but modifies self.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/corefines/hash.rb', line 22 module Compact refine ::Hash do def compact reject { |_, value| value.nil? } end def compact! delete_if { |_, value| value.nil? } end end end |