From 8f7d9eb043dbbca9e4b424c77e643312a9927eac Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Thu, 16 Apr 2015 16:46:03 -0700 Subject: 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. --- activerecord/lib/active_record/base.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') 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 - # read_attribute(attr_name) and write_attribute(attr_name, value) 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 self[:attribute]=(value) and self[:attribute] - # instead of write_attribute(:attribute, value) and read_attribute(:attribute). + # or write_attribute(:attribute, value) and read_attribute(:attribute). # # == Attribute query methods # -- cgit v1.2.3