Module: BulkDependencyEraser::Utils::Methods

Included in:
BulkDependencyEraser::Utils, BulkDependencyEraser::Utils
Defined in:
lib/bulk_dependency_eraser/utils.rb

Instance Method Summary collapse

Instance Method Details

#deep_freeze(obj) ⇒ Object

To freeze all nested structures including hashes, arrays, and strings Deep Freezing All Structures



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

def deep_freeze(obj)
  case obj
  when Hash
    obj.each { |key, value| deep_freeze(key); deep_freeze(value) }
    obj.freeze
  when Array
    obj.each { |value| deep_freeze(value) }
    obj.freeze
  when String
    obj.freeze
  else
    obj.freeze if obj.respond_to?(:freeze)
  end
end