diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-06-21 12:51:39 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-06-21 12:51:39 -0500 |
commit | b5b350ad5c1d115a54ab2ebadc44fa2d63ae50bf (patch) | |
tree | f965a37a636b8cb4966d1893214702572bea4676 /activemodel | |
parent | bf3332bfdf241832d0f0222f895392c48c91ed88 (diff) | |
download | rails-b5b350ad5c1d115a54ab2ebadc44fa2d63ae50bf.tar.gz rails-b5b350ad5c1d115a54ab2ebadc44fa2d63ae50bf.tar.bz2 rails-b5b350ad5c1d115a54ab2ebadc44fa2d63ae50bf.zip |
fix ActiveModel::AttributeMethods#alias_attribute documentation [ci skip]
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index dd144b6265..85e2f89931 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -78,8 +78,8 @@ module ActiveModel # at least the +attr+ argument. # # class Person - # # include ActiveModel::AttributeMethods + # # attr_accessor :name # attribute_method_prefix 'clear_' # define_attribute_methods :name @@ -114,8 +114,8 @@ module ActiveModel # least the +attr+ argument. # # class Person - # # include ActiveModel::AttributeMethods + # # attr_accessor :name # attribute_method_suffix '_short?' # define_attribute_methods :name @@ -150,8 +150,8 @@ module ActiveModel # 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 @@ -176,14 +176,27 @@ module ActiveModel # 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 @@ -200,8 +213,8 @@ module ActiveModel # methods, or they will not hook in. # # class Person - # # include ActiveModel::AttributeMethods + # # attr_accessor :name, :age, :address # attribute_method_prefix 'clear_' # |