我希望能够动态生成范围。假设我有以下模型:
class Product < ActiveRecord::Base
POSSIBLE_SIZES = [:small, :medium, :large]
scope :small, where(size: :small)
scope :medium, where(size: :medium)
scope :large, where(size: :large)
end
我们能否用基于 POSSIBLE_SIZES 常量的某些内容替换 scope
调用?我认为重复这些调用违反了 DRY 原则。