要旨
module M extend ActiveSupport::Concern included do scope :disabled, -> { where(disabled: true) } end class_methods do ... end end
https://github.com/rails/rails/blob/main/activesupport/lib/active_support/concern.rb より
詳細
included のブロックは、このモジュール M が include されたときに呼ばれる。なので、ここで scope や has_many 等の宣言ができる。
class_methods のブロックでは、クラスメソッドを定義することができる。ここのブロックで定義したメソッドは、全て自動的にクラスメソッドとして定義される。
他にも、includeする順番を考慮する必要が無くなる等のメリットがある。