Rails_constant_assignment

ネームスペース

Bad

  • 以下のようにネームスペース内に定数を定義しても読み込まれない
module Cs
  OrderType = Data.define(:name)
  class Order < ApplicationRecord
    # 省略
  end
end
Cs::OrderType
# => NameError: uninitialized constant #<Class:Ec>::OrderType

Good

  • それぞれ別で定義する
module Cs
  class Order < ApplicationRecord
    # 省略
  end
end
  • module内の定数はZeitwerkがおそらくファイル名を見ていると思われる
module Cs
  OrderType = Data.define(:name)
end