attribute_alias?

attribute_alias?(new_name) Instance Public methods Is new_name an alias?

attribute_method_affix

attribute_method_affix(*affixes) Instance Public methods Declares a method available for all attributes with the given prefix and suffix. Uses method_missing and respond_to? to rewrite the method. #{prefix}#{attr}#{suffix}(*args, &block) to #{prefix}attribute#{suffix}(#{attr}, *args, &block) An #{prefix}attribute#{suffix} instance method must exist and accept at least the attr argument. class Person include ActiveModel::AttributeMethods attr_accessor :name attribut

attribute_method_prefix

attribute_method_prefix(*prefixes) Instance Public methods Declares a method available for all attributes with the given prefix. Uses method_missing and respond_to? to rewrite the method. #{prefix}#{attr}(*args, &block) to #{prefix}attribute(#{attr}, *args, &block) An instance method #{prefix}attribute must exist and accept at least the attr argument. class Person include ActiveModel::AttributeMethods attr_accessor :name attribute_method_prefix 'clear_' define_at

attribute_method_suffix

attribute_method_suffix(*suffixes) Instance Public methods Declares a method available for all attributes with the given suffix. Uses method_missing and respond_to? to rewrite the method. #{attr}#{suffix}(*args, &block) to attribute#{suffix}(#{attr}, *args, &block) An attribute#{suffix} instance method must exist and accept at least the attr argument. class Person include ActiveModel::AttributeMethods attr_accessor :name attribute_method_suffix '_short?' define_a

define_attribute_method

define_attribute_method(attr_name) Instance Public methods Declares an attribute that should be prefixed and suffixed by ActiveModel::AttributeMethods. To use, pass an attribute name (as string or symbol), be sure to declare define_attribute_method after you define any prefix, suffix or affix method, or they will not hook in. class Person include ActiveModel::AttributeMethods attr_accessor :name attribute_method_suffix '_short?' # Call to define_attribute_method must appe

define_attribute_methods

define_attribute_methods(*attr_names) Instance Public methods 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_attr

undefine_attribute_methods

undefine_attribute_methods() Instance Public methods 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? # => No

attribute_missing

attribute_missing(match, *args, &block) Instance Public methods attribute_missing is like method_missing, but for attributes. When method_missing is called we check to see if there is a matching attribute method. If so, we tell attribute_missing to dispatch the attribute. This method can be overloaded to customize the behavior.

method_missing

method_missing(method, *args, &block) Instance Public methods Allows access to the object attributes, which are held in the hash returned by attributes, as though they were first-class methods. So a Person class with a name attribute can for example use Person#name and Person#name= and never directly use the attributes hash â except for multiple assigns with ActiveRecord::Base#attributes=. It's also possible to instantiate related objects, so a Client class belonging to the cli

respond_to?

respond_to?(method, include_private_methods = false) Instance Public methods Also aliased as: respond_to_without_attributes?