Method: ActiveModel::AttributeMethods::ClassMethods#undefine_attribute_methods
- Defined in:
- activemodel/lib/active_model/attribute_methods.rb
#undefine_attribute_methods ⇒ Object
Removes all the previously dynamically defined methods from the class, including alias attribute methods.
class Person
include ActiveModel::AttributeMethods
attr_accessor :name
attribute_method_suffix '_short?'
define_attribute_method :name
alias_attribute :first_name, :name
private
def attribute_short?(attr)
send(attr).length < 5
end
end
person = Person.new
person.name = 'Bob'
person.first_name # => "Bob"
person.name_short? # => true
Person.undefine_attribute_methods
person.name_short? # => NoMethodError
person.first_name # => NoMethodError
375 376 377 378 379 380 |
# File 'activemodel/lib/active_model/attribute_methods.rb', line 375 def undefine_attribute_methods generated_attribute_methods.module_eval do undef_method(*instance_methods) end attribute_method_patterns_cache.clear end |