Flowdock
method

attribute_method_suffix

Importance_2
Ruby on Rails latest stable (v6.1.7.7) - 0 notes - Class: ActiveRecord::AttributeMethods::ClassMethods

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

These similar methods exist in v6.1.7.7:

attribute_method_suffix(*suffixes) public

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
Show source
Register or log in to add new notes.