Module: ActiveJsonModel::Utils

Defined in:
lib/active_json_model/utils.rb

Class Method Summary collapse

Class Method Details

.recursively_make_indifferent(val) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_json_model/utils.rb', line 7

def self.recursively_make_indifferent(val)
  return val unless val&.is_a?(Hash) || val&.respond_to?(:map)

  if val.is_a?(Hash)
    val.with_indifferent_access.tap do |w|
      w.each do |k, v|
        w[k] = recursively_make_indifferent(v)
      end
    end
  else
    val.map do |v|
      recursively_make_indifferent(v)
    end
  end
end