Module: NCore::Util

Extended by:
ActiveSupport::Concern
Defined in:
lib/ncore/util.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.deep_clone(value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ncore/util.rb', line 5

def self.deep_clone(value)
  case value
  when Hash
    cl = value.clone
    value.each{|k,v| cl[k] = deep_clone(v)}
    cl
  when Array
    cl = value.clone
    cl.clear
    value.each{|v| cl << deep_clone(v)}
    cl
  when NilClass, Numeric, TrueClass, FalseClass
    value
  else
    value.clone rescue value
  end
end