Allows you to make aliases for attributes, which includes getter, setter, and query methods.
Example:
class Content < ActiveRecord::Base # has a title attribute end class Email < Content alias_attribute :subject, :title end e = Email.find(1) e.title # => "Superstars" e.subject # => "Superstars" e.subject? # => true e.subject = "Megastars" e.title # => "Megastars"
Source Code
# File active_support/core_ext/module/aliasing.rb, line 63 def alias_attribute(new_name, old_name) module_eval "def \#{new_name}; self.\#{old_name}; end\ndef \#{new_name}?; self.\#{old_name}?; end\ndef \#{new_name}=(v); self.\#{old_name} = v; end\n", __FILE__, __LINE__+1 end
<code/>and<pre/>for code samples.