Skip to content

Commit b0994d0

Browse files
committed
Merge pull request rails#19787 from Senjai/patch-2
[Doc] Encourage users to user super to override methods. [ci skip]
1 parent c713ec9 commit b0994d0

File tree

1 file changed

+4
-5
lines changed
  • activerecord/lib/active_record

1 file changed

+4
-5
lines changed

activerecord/lib/active_record/base.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,22 @@ module ActiveRecord #:nodoc:
119119
# All column values are automatically available through basic accessors on the Active Record
120120
# object, but sometimes you want to specialize this behavior. This can be done by overwriting
121121
# the default accessors (using the same name as the attribute) and calling
122-
# <tt>read_attribute(attr_name)</tt> and <tt>write_attribute(attr_name, value)</tt> to actually
123-
# change things.
122+
# +super+ to actually change things.
124123
#
125124
# class Song < ActiveRecord::Base
126125
# # Uses an integer of seconds to hold the length of the song
127126
#
128127
# def length=(minutes)
129-
# write_attribute(:length, minutes.to_i * 60)
128+
# super(minutes.to_i * 60)
130129
# end
131130
#
132131
# def length
133-
# read_attribute(:length) / 60
132+
# super / 60
134133
# end
135134
# end
136135
#
137136
# You can alternatively use <tt>self[:attribute]=(value)</tt> and <tt>self[:attribute]</tt>
138-
# instead of <tt>write_attribute(:attribute, value)</tt> and <tt>read_attribute(:attribute)</tt>.
137+
# or <tt>write_attribute(:attribute, value)</tt> and <tt>read_attribute(:attribute)</tt>.
139138
#
140139
# == Attribute query methods
141140
#

0 commit comments

Comments
 (0)