Skip to content

Commit

Permalink
fix ActiveModel::AttributeMethods#alias_attribute documentation [ci s…
Browse files Browse the repository at this point in the history
…kip]
  • Loading branch information
Francesco Rodriguez committed Jun 21, 2012
1 parent bf3332b commit b5b350a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions activemodel/lib/active_model/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ module ClassMethods
# at least the +attr+ argument.
#
# class Person
#
# include ActiveModel::AttributeMethods
#
# attr_accessor :name
# attribute_method_prefix 'clear_'
# define_attribute_methods :name
Expand Down Expand Up @@ -114,8 +114,8 @@ def attribute_method_prefix(*prefixes)
# least the +attr+ argument.
#
# class Person
#
# include ActiveModel::AttributeMethods
#
# attr_accessor :name
# attribute_method_suffix '_short?'
# define_attribute_methods :name
Expand Down Expand Up @@ -150,8 +150,8 @@ def attribute_method_suffix(*suffixes)
# accept at least the +attr+ argument.
#
# class Person
#
# include ActiveModel::AttributeMethods
#
# attr_accessor :name
# attribute_method_affix prefix: 'reset_', suffix: '_to_default!'
# define_attribute_methods :name
Expand All @@ -176,14 +176,27 @@ def attribute_method_affix(*affixes)
# Allows you to make aliases for attributes.
#
# class Person
# include ActiveModel::AttributeMethods
#
# attr_accessor :name
# attribute_method_suffix '_short?'
# define_attribute_methods :name
#
# alias_attribute :nickname, :name
#
# private
#
# def attribute_short?(attr)
# send(attr).length < 5
# end
# end
#
# person = Person.new
# person.nickname = 'Bob'
# person.nickname # => "Bob"
# person.name # => "Bob"
# person.name = 'Bob'
# person.name # => "Bob"
# person.nickname # => "Bob"
# person.name_short? # => true
# person.nickname_short? # => true
def alias_attribute(new_name, old_name)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s
Expand All @@ -200,8 +213,8 @@ def alias_attribute(new_name, old_name)
# methods, or they will not hook in.
#
# class Person
#
# include ActiveModel::AttributeMethods
#
# attr_accessor :name, :age, :address
# attribute_method_prefix 'clear_'
#
Expand Down

0 comments on commit b5b350a

Please sign in to comment.