Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/remocon/util/hash.rb

Instance Method Summary collapse

Instance Method Details

#skip_nil_valuesObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/remocon/util/hash.rb', line 4

def skip_nil_values
  dup.compact.each_with_object({}) do |(k, v), acc|
    next if v.nil?
    acc[k] = case v
             when Hash
               v.skip_nil_values
             when Array
               v.compact
             else
               v
             end
  end
end

#stringify_valuesObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/remocon/util/hash.rb', line 18

def stringify_values
  self.deep_merge(self) do |_, _, v|
    if v.kind_of?(Hash)
      v.stringify_values
    elsif v.kind_of?(Array)
      v.stringify_values
    else
      v.to_s
    end
  end
end