module ActiveModel::AttributeMethods::ClassMethods
def alias_attribute(new_name, old_name)
person.name_short? # => true
person.nickname # => "Bob"
person.name # => "Bob"
person.name = 'Bob'
person = Person.new
end
end
send(attr).length < 5
def attribute_short?(attr)
private
alias_attribute :nickname, :name
define_attribute_methods :name
attribute_method_suffix '_short?'
attr_accessor :name
include ActiveModel::AttributeMethods
class Person
Allows you to make aliases for attributes.
def alias_attribute(new_name, old_name) old_name = old_name.to_s new_name = new_name.to_s self.attribute_aliases = attribute_aliases.merge(new_name => old_name) aliases_by_attribute_name[old_name] << new_name eagerly_generate_alias_attribute_methods(new_name, old_name) end