Module: Mongoid::Attributes::ClassMethods

Defined in:
lib/mongoid/attributes.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#alias_attribute(name, original) ⇒ Object

Alias the provided name to the original field. This will provide an aliased getter, setter, existance check, and all dirty attribute methods.

Examples:

Alias the attribute.

class Product
  include Mongoid::Document
  field :price, :type => Float
  alias_attribute :cost, :price
end

Parameters:

  • name (Symbol)

    The new name.

  • original (Symbol)

    The original name.

Since:

  • 2.3.0



224
225
226
227
228
229
230
231
# File 'lib/mongoid/attributes.rb', line 224

def alias_attribute(name, original)
  class_eval <<-RUBY
    alias :#{name} :#{original}
    alias :#{name}= :#{original}=
    alias :#{name}? :#{original}?
  RUBY
  super
end