Method: Attributor.recursive_to_h

Defined in:
lib/attributor.rb

.recursive_to_h(val) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/attributor.rb', line 71

def self.recursive_to_h(val)
  if val.is_a? Array
    val.map { |v| recursive_to_h(v) }
  elsif val.nil?
    nil
  elsif val.respond_to?(:to_h)
    val.to_h.each_with_object({}) do |(name, inner_val), hash|
      hash[name] = recursive_to_h(inner_val)
    end
  else
    val
  end
end