method
define_attribute_methods
v4.2.1 -
Show latest stable
-
0 notes -
Class: ActiveModel::AttributeMethods::ClassMethods
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-38)
- 3.1.0 (-2)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-15)
- 4.1.8 (16)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (11)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (-1)
- 7.1.3.4 (0)
- What's this?
define_attribute_methods(*attr_names)
public
Declares the attributes that should be prefixed and suffixed by ActiveModel::AttributeMethods.
To use, pass attribute names (as strings or symbols), be sure to declare define_attribute_methods after you define any prefix, suffix or affix methods, or they will not hook in.
class Person include ActiveModel::AttributeMethods attr_accessor :name, :age, :address attribute_method_prefix 'clear_' # Call to define_attribute_methods must appear after the # attribute_method_prefix, attribute_method_suffix or # attribute_method_affix declares. define_attribute_methods :name, :age, :address private def clear_attribute(attr) send("#{attr}=", nil) end end