module Magick::RVG::Duplicatable

def deep_copy(h = {})

def deep_copy(h = {})
    # Prevent recursion. If we reach the
    # object we started with, stop copying.
    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
    copy
end