Module: HashWithDotAccess::Utils

Defined in:
lib/hash_with_dot_access.rb

Class Method Summary collapse

Class Method Details

.normalized_value(obj, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/hash_with_dot_access.rb', line 3

def self.normalized_value(obj, value)
  return value if value.instance_of?(obj.class)

  case value
  when ::Hash
    obj.class.new(value)
  when Array
    value = value.dup if value.frozen?
    value.map! { normalized_value(obj, _1) }
  else
    value
  end
end

.primitive_value(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/hash_with_dot_access.rb', line 17

def self.primitive_value(value)
  case value
  when ::Hash  
    value.to_h
  when Array
    value.map { primitive_value(_1) }
  else
    value
  end
end