diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-10-28 19:43:21 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-11-02 17:14:52 +0100 |
commit | 5071b727b438f1ca6be502c906f5af751abb0229 (patch) | |
tree | fba52afb44767c7d594a48c446bcbac8daff5886 /activesupport/lib/active_support | |
parent | cfbe5958311f21397c98657c3370d03dcf720fe1 (diff) | |
download | rails-5071b727b438f1ca6be502c906f5af751abb0229.tar.gz rails-5071b727b438f1ca6be502c906f5af751abb0229.tar.bz2 rails-5071b727b438f1ca6be502c906f5af751abb0229.zip |
Added Hash#deep_dup function which performs deep duplication on given hash
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/deep_dup.rb | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash.rb b/activesupport/lib/active_support/core_ext/hash.rb index 501483498d..fd1cda991e 100644 --- a/activesupport/lib/active_support/core_ext/hash.rb +++ b/activesupport/lib/active_support/core_ext/hash.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/hash/conversions' require 'active_support/core_ext/hash/deep_merge' +require 'active_support/core_ext/hash/deep_dup' require 'active_support/core_ext/hash/diff' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/indifferent_access' diff --git a/activesupport/lib/active_support/core_ext/hash/deep_dup.rb b/activesupport/lib/active_support/core_ext/hash/deep_dup.rb new file mode 100644 index 0000000000..447142605c --- /dev/null +++ b/activesupport/lib/active_support/core_ext/hash/deep_dup.rb @@ -0,0 +1,11 @@ +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 |