回答編集履歴

1

マークダウンを修正

2023/01/03 04:46

投稿

Hanbe.T
Hanbe.T

スコア36

test CHANGED
@@ -12,21 +12,21 @@
12
12
  accessorsを定義しなくても、デフォルトでaccessorsが生成される。
13
13
  ActiveRecodが提供する`accessors`では`super`に対して処理をしているのに対して、[Rubyが提供する`accessors`](https://docs.ruby-lang.org/ja/latest/method/Module/i/attr_accessor.html)では、自クラスに対してなので、ActiveRecordとしては処理されなかったのですね。
14
14
  > This would also define the following accessors: Product#name and Product#name=(new_name).
15
- 引用:https://api.rubyonrails.org/files/activerecord/README_rdoc.html
15
+ > 引用:https://api.rubyonrails.org/files/activerecord/README_rdoc.html
16
16
 
17
17
  > 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 super to actually change things.
18
- ```ruby
18
+ > ```ruby
19
- class Song < ActiveRecord::Base
19
+ > class Song < ActiveRecord::Base
20
- # Uses an integer of seconds to hold the length of the song
20
+ > # Uses an integer of seconds to hold the length of the song
21
+ >
22
+ > def length=(minutes)
23
+ > super(minutes.to_i * 60)
24
+ > end
25
+ >
26
+ > def length
27
+ > super / 60
28
+ > end
29
+ > end
30
+ > ```
31
+ > 引用:[Overwriting default accessors](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#:~:text=Overwriting%20default%20accessors)
21
32
 
22
- def length=(minutes)
23
- super(minutes.to_i * 60)
24
- end
25
-
26
- def length
27
- super / 60
28
- end
29
- end
30
- ```
31
- 引用:[Overwriting default accessors](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#:~:text=Overwriting%20default%20accessors)
32
-