Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/utils/hash_with_compact.rb
Overview
borrowing from rails implementation github.com/rails/rails/blob/c0357d789b4323da64f1f9f82fa720ec9bac17cf/activesupport/lib/active_support/core_ext/hash/compact.rb#L8
Instance Method Summary collapse
Instance Method Details
#compact ⇒ Object
: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_empty ⇒ Object
42 43 44 45 |
# File 'lib/utils/hash_with_compact.rb', line 42 def compact_and_check_if_empty self.compact! self.empty? end |