Skip to content

Commit

Permalink
[Docs] Update undefine_attribute_methods docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nvasilevski committed Aug 23, 2023
1 parent dd6d931 commit 5bc904d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion activemodel/lib/active_model/attribute_methods.rb
Expand Up @@ -333,14 +333,15 @@ def define_attribute_method(attr_name, _owner: generated_attribute_methods)
end
end

# Removes all the previously dynamically defined methods from the class.
# 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)
Expand All @@ -350,11 +351,13 @@ def define_attribute_method(attr_name, _owner: generated_attribute_methods)
#
# 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
def undefine_attribute_methods
generated_attribute_methods.module_eval do
undef_method(*instance_methods)
Expand Down

0 comments on commit 5bc904d

Please sign in to comment.