method

define_attr_method

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveRecord::Base

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.

define_attr_method(name, value=nil, &block) private

Defines an "attribute" method (like inheritance_column or table_name). A new (class) method will be created with the given name. If a value is specified, the new method will return that value (as a string). Otherwise, the given block will be used to compute the value of the method.

The original method will be aliased, with the new name being prefixed with "original_". This allows the new method to access the original value.

Example:

  class A < ActiveRecord::Base
    define_attr_method :primary_key, "sysid"
    define_attr_method( :inheritance_column ) do
      original_inheritance_column + "_id"
    end
  end
Show source
Register or log in to add new notes.