lib/mongoid/attributes.rb
# Alias the provided name to the original field. This will provide an
# aliased getter, setter, existance check, and all dirty attribute
# methods.
#
# @example Alias the attribute.
#   class Product
#     include Mongoid::Document
#     field :price, :type => Float
#     alias_attribute :cost, :price
#   end
#
# @param [ Symbol ] name The new name.
# @param [ Symbol ] original The original name.
#
# @since 2.3.0
Alias the provided name to the original field. This will provide an
aliased getter, setter, existance check, and all dirty attribute
methods.
Alias the provided name to the original field . This will provide an aliased getter setter existance check and all dirty attribute methods .
def alias_attribute(name, original)
        class_eval <<-RUBY
          alias #{name}  #{original}
          alias #{name}= #{original}=
          alias #{name}? #{original}?
          alias #{name}_change   #{original}_change
          alias #{name}_changed? #{original}_changed?
          alias reset_#{name}!   reset_#{original}!
          alias #{name}_was      #{original}_was
          alias #{name}_will_change! #{original}_will_change!
          alias #{name}_before_type_cast #{original}_before_type_cast
        RUBY
      end
def alias_attribute ( name , original ) class_eval <<-RUBY 
          alias  #{ name } #{ original } 
          alias  #{ name } =  #{ original } =
          alias  #{ name } ?  #{ original } ?
          alias  #{ name } _change    #{ original } _change
          alias  #{ name } _changed?  #{ original } _changed?
          alias reset_ #{ name } !   reset_ #{ original } !
          alias  #{ name } _was       #{ original } _was
          alias  #{ name } _will_change!  #{ original } _will_change!
          alias  #{ name } _before_type_cast  #{ original } _before_type_cast
         RUBY end
Alias the provided name to the original field.
Alias the provided name to the original field .
name
original
original The original name.
original The original name .
example
Alias the attribute. class Product include Mongoid::Document field :price, :type => Float alias_attribute :cost, :price end
Alias the attribute . class Product include Mongoid :: Document field : price : type = > Float alias_attribute : cost : price end
since
None