instance method attribute_method_suffix

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

attribute_method_suffix(*suffixes)

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.

For example:

class Person < ActiveRecord::Base
  attribute_method_suffix '_changed?'

  private
    def attribute_changed?(attr)
      ...
    end
end

person = Person.find(1)
person.name_changed?    # => false
person.name = 'Hubert'
person.name_changed?    # => true

Parameters

suffixes rest
Source
# File activerecord/lib/active_record/attribute_methods.rb, line 46
      def attribute_method_suffix(*suffixes)
        attribute_method_suffixes.concat suffixes
        rebuild_attribute_method_regexp
      end

Defined in activerecord/lib/active_record/attribute_methods.rb line 46 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::AttributeMethods::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close