Sha256: f0b6d30bdcf58f2893d52a08221da86161ff1faf5be2e08364f93cd755d4f66f
Contents?: true
Size: 1.15 KB
Versions: 14
Compression:
Stored size: 1.15 KB
Contents
class Object def deep_clone clone = self.clone instance_variables.each do |name| value = instance_variable_get name clone.instance_variable_set name, value.deep_clone end clone end end Hash.class_eval do def deep_clone clone = super clone.clear each{|k, v| clone[k.deep_clone] = v.deep_clone} clone end end OpenObject.class_eval do def deep_clone clone = super clone.clear each{|k, v| clone[k.deep_clone] = v.deep_clone} clone end end Struct.class_eval do def deep_clone clone = super clone.clear each_pair{|k, v| clone[k.deep_clone] = v.deep_clone} clone end end Array.class_eval do def deep_clone clone = super clone.clear each{|v| clone << v.deep_clone} clone end end [Class, Proc, Regexp].each do |klass| klass.class_eval do def clone; self end alias_method :deep_clone, :clone end end [Symbol, TrueClass, FalseClass, Numeric, TrueClass, FalseClass, NilClass].each do |klass| klass.send :alias_method, :clone, :self end [String, Symbol, Range, Regexp, Time, Date].each do |klass| klass.send :alias_method, :deep_clone, :clone end
Version data entries
14 entries across 14 versions & 1 rubygems