Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/hash_with_compact.rb

Overview

Instance Method Summary collapse

Instance Method Details

#compactObject

:nodoc: all



34
35
36
# File 'lib/utils/hash_with_compact.rb', line 34

def compact
  self.select { |_, value| value.is_a?(Hash) ? !value.compact_and_check_if_empty : !value.nil? }
end

#compact!Object



38
39
40
# File 'lib/utils/hash_with_compact.rb', line 38

def compact!
  self.reject! {|_, value| value.is_a?(Hash) ? value.compact_and_check_if_empty : value.nil? }
end

#compact_and_check_if_emptyObject



42
43
44
45
# File 'lib/utils/hash_with_compact.rb', line 42

def compact_and_check_if_empty
  self.compact!
  self.empty?
end