aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_methods.rb
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-07 22:47:35 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-07 22:47:35 -0500
commit4831a895c445f650c9daf0b445136ceb653f781b (patch)
tree8db322e88af4bb86d85d78f8faa980ee8084eccc /activemodel/lib/active_model/attribute_methods.rb
parent2805c28e3e9a7386fe144754a9b664c424add2b3 (diff)
downloadrails-4831a895c445f650c9daf0b445136ceb653f781b.tar.gz
rails-4831a895c445f650c9daf0b445136ceb653f781b.tar.bz2
rails-4831a895c445f650c9daf0b445136ceb653f781b.zip
added docs to alias_attribute method
Diffstat (limited to 'activemodel/lib/active_model/attribute_methods.rb')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 97a83e58af..59977b6142 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -180,6 +180,37 @@ module ActiveModel
undefine_attribute_methods
end
+
+ # Allows you to make aliases for attributes.
+ #
+ # For example:
+ #
+ # class Person
+ #
+ # include ActiveModel::AttributeMethods
+ # attr_accessor :name
+ # attribute_method_prefix 'clear_'
+ #
+ # define_attribute_methods [:name]
+ #
+ # private
+ #
+ # def clear_attribute(attr)
+ # send("#{attr}=", nil)
+ # end
+ # end
+ #
+ # class Person
+ # attr_accessor :nickname
+ #
+ # alias_attribute :nickname, :name
+ # end
+ #
+ # person = Person.new
+ # person.nickname = "Bob"
+ # person.nickname # => "Bob"
+ # person.clear_nickname
+ # person.nickname # => nil
def alias_attribute(new_name, old_name)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s