aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRichard Wilson <r.crawfordwilson@gmail.com>2015-04-16 16:46:03 -0700
committerRichard Wilson <r.crawfordwilson@gmail.com>2015-04-16 16:46:03 -0700
commit8f7d9eb043dbbca9e4b424c77e643312a9927eac (patch)
tree178140ef1c4f8974a64ec215f5c7b9ec71d57308 /activerecord
parentc8bab30ce5a7a40be7a3c7c4271e8ae6d2b303bb (diff)
downloadrails-8f7d9eb043dbbca9e4b424c77e643312a9927eac.tar.gz
rails-8f7d9eb043dbbca9e4b424c77e643312a9927eac.tar.bz2
rails-8f7d9eb043dbbca9e4b424c77e643312a9927eac.zip
Encourage users to user super to override methods.
IMO we shouldn't encourage users to use methods they shouldn't need to know about. As Song (in this example) inherits from ActiveRecord, we can use super here instead to get the same effect with the bonus of not knowing how active record actually implements these methods.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/base.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 67490ecd97..c8f8f2c3d8 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -120,23 +120,22 @@ module ActiveRecord #:nodoc:
# All column values are automatically available through basic accessors on the Active Record
# object, but sometimes you want to specialize this behavior. This can be done by overwriting
# the default accessors (using the same name as the attribute) and calling
- # <tt>read_attribute(attr_name)</tt> and <tt>write_attribute(attr_name, value)</tt> to actually
- # change things.
+ # super to actually change things.
#
# class Song < ActiveRecord::Base
# # Uses an integer of seconds to hold the length of the song
#
# def length=(minutes)
- # write_attribute(:length, minutes.to_i * 60)
+ # super(minutes.to_i * 60)
# end
#
# def length
- # read_attribute(:length) / 60
+ # super / 60
# end
# end
#
# You can alternatively use <tt>self[:attribute]=(value)</tt> and <tt>self[:attribute]</tt>
- # instead of <tt>write_attribute(:attribute, value)</tt> and <tt>read_attribute(:attribute)</tt>.
+ # or <tt>write_attribute(:attribute, value)</tt> and <tt>read_attribute(:attribute)</tt>.
#
# == Attribute query methods
#