diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/class')
-rw-r--r-- | activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb index 3c5b2b8340..d8283760b9 100644 --- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb @@ -89,10 +89,13 @@ class Class # :nodoc: end def inheritable_attributes - @inheritable_attributes ||= {} + @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES end def write_inheritable_attribute(key, value) + if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES) + inheritable_attributes = {} + end inheritable_attributes[key] = value end @@ -111,15 +114,21 @@ class Class # :nodoc: end def reset_inheritable_attributes - inheritable_attributes.clear + @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES end - private + private + EMPTY_INHERITABLE_ATTRIBUTES = {}.freeze + def inherited_with_inheritable_attributes(child) inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes) - new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)| - memo.update(key => (value.dup rescue value)) + if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES) + new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES + else + new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)| + memo.update(key => (value.dup rescue value)) + end end child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes) |