class SafeYAML::Deep

def self.copy(object)

def self.copy(object)
  duplicate = object.dup rescue object
  case object
  when Array
    (0...duplicate.count).each do |i|
      duplicate[i] = Deep.copy(duplicate[i])
    end
  when Hash
    duplicate.keys.each do |key|
      duplicate[key] = Deep.copy(duplicate[key])
    end
  end
  duplicate
end

def self.freeze(object)

def self.freeze(object)
  object.each do |*entry|
    value = entry.last
    case value
    when String, Regexp
      value.freeze
    when Enumerable
      Deep.freeze(value)
    end
  end
  return object.freeze
end