Module: ActiveSupport::ClassAttribute
- Defined in:
- lib/active_support/class_attribute.rb
Overview
:nodoc:
Class Method Summary collapse
- .redefine(owner, name, namespaced_name, value) ⇒ Object
- .redefine_method(owner, name, private: false, &block) ⇒ Object
Class Method Details
.redefine(owner, name, namespaced_name, value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_support/class_attribute.rb', line 6 def redefine(owner, name, namespaced_name, value) if owner.singleton_class? if owner.attached_object.is_a?(Module) redefine_method(owner, namespaced_name, private: true) { value } else redefine_method(owner, name) { value } end end redefine_method(owner.singleton_class, namespaced_name, private: true) { value } redefine_method(owner.singleton_class, "#{namespaced_name}=", private: true) do |new_value| if owner.equal?(self) value = new_value else ::ActiveSupport::ClassAttribute.redefine(self, name, namespaced_name, new_value) end end end |
.redefine_method(owner, name, private: false, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/active_support/class_attribute.rb', line 26 def redefine_method(owner, name, private: false, &block) owner.silence_redefinition_of_method(name) owner.define_method(name, &block) owner.send(:private, name) if private end |