diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-07-10 13:32:59 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-07-10 13:32:59 -0300 |
commit | ebf8961182bdc8134cc4b21dfa46b909624b6126 (patch) | |
tree | 468d1e18ca0ac0680e0e4c15fd296de874ff109b /activesupport/lib/active_support | |
parent | eb10496a1c3d9fe58b91aa0ec17d9f218738d5dc (diff) | |
parent | 9578d574f3be8da966ee7355dfb1604936a103cb (diff) | |
download | rails-ebf8961182bdc8134cc4b21dfa46b909624b6126.tar.gz rails-ebf8961182bdc8134cc4b21dfa46b909624b6126.tar.bz2 rails-ebf8961182bdc8134cc4b21dfa46b909624b6126.zip |
Merge pull request #20828 from Sirupsen/hash-indifferent-dup-default-proc
active_support/indifferent_access: fix not raising when default_proc does
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 4f71f13971..63690a1342 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -188,7 +188,7 @@ module ActiveSupport # dup[:a][:c] # => "c" def dup self.class.new(self).tap do |new_hash| - new_hash.default = default + set_defaults(new_hash) end end @@ -247,7 +247,9 @@ module ActiveSupport # Convert to a regular hash with string keys. def to_hash - _new_hash = Hash.new(default) + _new_hash = Hash.new + set_defaults(_new_hash) + each do |key, value| _new_hash[key] = convert_value(value, for: :to_hash) end @@ -275,6 +277,14 @@ module ActiveSupport value end end + + def set_defaults(target) + if default_proc + target.default_proc = default_proc.dup + else + target.default = default + end + end end end |