diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-06-21 16:19:40 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-06-21 16:19:40 -0500 |
commit | 95a938a5e69a0513a3666f5979be2460fa717885 (patch) | |
tree | 804a3edd4623463afbda2a12d97817cedcc9f01c /activemodel/lib | |
parent | f975c4b641b4d410b7d2ef654bba549e1dfb652e (diff) | |
download | rails-95a938a5e69a0513a3666f5979be2460fa717885.tar.gz rails-95a938a5e69a0513a3666f5979be2460fa717885.tar.bz2 rails-95a938a5e69a0513a3666f5979be2460fa717885.zip |
add example to ActiveModel::AttributeMethods#undefine_attribute_methods [ci skip]
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 96d44e3b0d..a869991280 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -245,6 +245,10 @@ module ActiveModel # # attr_accessor :name # attribute_method_suffix '_short?' + # + # # Call to define_attribute_method must appear after the + # # attribute_method_prefix, attribute_method_suffix or + # # attribute_method_affix declares. # define_attribute_method :name # # private @@ -276,6 +280,28 @@ module ActiveModel end # Removes all the previously dynamically defined methods from the class + # + # class Person + # include ActiveModel::AttributeMethods + # + # attr_accessor :name + # attribute_method_suffix '_short?' + # define_attribute_method :name + # + # private + # + # def attribute_short?(attr) + # send(attr).length < 5 + # end + # end + # + # person = Person.new + # person.name = 'Bob' + # person.name_short? # => true + # + # Person.undefine_attribute_methods + # + # person.name_short? # => NoMethodError def undefine_attribute_methods generated_attribute_methods.module_eval do instance_methods.each { |m| undef_method(m) } |