module Corefines::Hash::Compact
@!method compact
@example hash = { a: true, b: false, c: nil } hash.compact # => { a: true, b: false } hash # => { a: true, b: false, c: nil } { c: nil }.compact # => {} @return [Hash] a new hash with no key-value pairs which value is +nil+.
@!method compact!
Removes all key-value pairs from the hash which value is +nil+. Same as {#compact}, but modifies +self+. @return [Hash] self
Public Instance Methods
compact()
click to toggle source
# File lib/corefines/hash.rb, line 24 def compact reject { |_, value| value.nil? } end
compact!()
click to toggle source
# File lib/corefines/hash.rb, line 28 def compact! delete_if { |_, value| value.nil? } end