def deep_copy(h = {})
copy = h[__id__]
unless copy
h[__id__] = copy = self.class.allocate
ivars = instance_variables
ivars.each do |ivar|
ivalue = instance_variable_get(ivar)
cvalue = case
when NilClass === ivalue, Symbol === ivalue, Float === ivalue,
Fixnum === ivalue, FalseClass === ivalue, TrueClass === ivalue
ivalue
when ivalue.respond_to?(:deep_copy)
ivalue.deep_copy(h)
when ivalue.respond_to?(:dup)
ivalue.dup
else
ivalue
end
copy.instance_variable_set(ivar, cvalue)
end
copy.freeze if frozen?
end
return copy
end