class Module
def alias_attribute(new_name, old_name)
e.subject = "Megastars"
e.subject? # => true
e.subject # => "Superstars"
e.title # => "Superstars"
e = Email.find(1)
end
alias_attribute :subject, :title
class Email < Content
end
# has a title attribute
class Content < ActiveRecord::Base
getter, setter, and a predicate.
Allows you to make aliases for attributes, which includes
def alias_attribute(new_name, old_name) # The following reader methods use an explicit `self` receiver in order to # support aliases that start with an uppercase letter. Otherwise, they would # be resolved as constants instead. module_eval <<-STR, __FILE__, __LINE__ + 1 def #{new_name}; self.#{old_name}; end # def subject; self.title; end def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end def #{new_name}=(v); self.#{old_name} = v; end # def subject=(v); self.title = v; end STR end