Module: AngryHash::Conversion::ByReference

Included in:
AngryHash
Defined in:
lib/angry_hash/conversion/by_reference.rb

Instance Method Summary collapse

Instance Method Details

#__convert_value_without_dup(v) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/angry_hash/conversion/by_reference.rb', line 13

def __convert_value_without_dup(v)
  v = v.to_hash if v.respond_to?(:to_hash)

  case v
  when AngryHash
    v
  when Hash
    __convert_without_dup(v)
  when Array
    v.map {|vv| __convert_value_without_dup(vv)}
  else
    v
  end
end

#__convert_without_dup(hash) ⇒ Object

non-duplicating convert



6
7
8
9
10
11
# File 'lib/angry_hash/conversion/by_reference.rb', line 6

def __convert_without_dup(hash)
  hash.inject(AngryHash.new) do |newhash,(k,v)|
    newhash[__convert_key(k)] = __convert_value_without_dup(v)
    newhash
  end
end