Permalink
Browse files

simplify the alias_attribute example [ci skip]

  • Loading branch information...
vijaydev committed May 8, 2012
1 parent f31613a commit 7e26f7f0f7e3c230c333e1b265727a9b8cf7c91f
Showing with 1 addition and 20 deletions.
  1. +1 −20 activemodel/lib/active_model/attribute_methods.rb
@@ -183,34 +183,15 @@ def attribute_method_affix(*affixes)
# 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
+ # person.name # => "Bob"
def alias_attribute(new_name, old_name)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s

0 comments on commit 7e26f7f

Please sign in to comment.