17 lines
431 B
Ruby
17 lines
431 B
Ruby
# TODO: Delete this file when we drop support for Rails 3.0
|
|
# This method is already implemented in active_support 3.1
|
|
|
|
unless Hash.new.respond_to?(:deep_dup)
|
|
class Hash
|
|
# Returns a deep copy of hash.
|
|
def deep_dup
|
|
duplicate = self.dup
|
|
duplicate.each_pair do |k,v|
|
|
tv = duplicate[k]
|
|
duplicate[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_dup : v
|
|
end
|
|
duplicate
|
|
end
|
|
end
|
|
end
|