From 95a938a5e69a0513a3666f5979be2460fa717885 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 21 Jun 2012 16:19:40 -0500 Subject: add example to ActiveModel::AttributeMethods#undefine_attribute_methods [ci skip] --- activemodel/lib/active_model/attribute_methods.rb | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'activemodel/lib/active_model') 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) } -- cgit v1.2.3