method

define_attr_method

Importance_2
v2.3.8 - Show latest stable - 0 notes - Class: ActiveRecord::Base
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.