为什么 class 模块 ClassMethod 的方法在这里不可用

Why aren't class methods available here with module ClassMethod

Ruby 2.6.3 ; Rails6.0.3

我有一个模块和一个包含它的 class,但我无法在 class 上提供任何 class 方法,只有实例方法

module Importable
  def self.inlcuded(base)
    base.extend ClassMethods

    base.class_eval do
      scope :from_source_a, -> { where(import_source: "source_a") }
    end
  end

  def from_source_a?
    self.import_source == "source_a"
  end

  module ClassMethods
    def find_from_source_a(id)
      self.find_by(
        import_source: "source_a",
        import_id: id
      )
    end
  end
end

class Employee < ApplicationRecord
  include Importable
end

所以

Employee.first.from_source_a? 有效 但 Employee.find_from_source_a(id) 抛出 NoMethodError: undefined method find_from_source_a for Employee

但我正在查看的示例使它看起来应该可行。关于我在这里出错的任何想法?

你好像打错了。

self.included(base) 不是 self.inlcuded(base)