Module: Dedup::Ruby

Extended by:
Ruby
Included in:
Ruby
Defined in:
lib/dedup.rb

Instance Method Summary collapse

Instance Method Details

#deep_intern!(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dedup.rb', line 14

def deep_intern!(data)
  case data
  when Hash
    return EMPTY_HASH if data.empty?
    return data if data.frozen?

    data.transform_keys! { |k| deep_intern!(k) }
    data.transform_values! { |v| deep_intern!(v) }
    data.freeze
  when Array
    return EMPTY_ARRAY if data.empty?
    return data if data.frozen?

    data.map! { |d| deep_intern!(d) }.freeze
  when String
    -data.freeze
  else
    data.freeze
  end
end