0

所以我正在编写一个包含多个 lib 文件的 gem,每个文件都包含相同模块的类,如下所示:

主“加载器”库

#lib/jobhandler.rb

require 'jobhandler/job'

module JobHandler
end

另一个文件中相同模块的另一个类

#lib/jobhandler/job.rb

module JobHandler
  class Job < ActiveRecord::Base
    def self.class_thingy
      return "I am a class method"
    end

    def instance_thingy
      return "I am an instance method of a class inside a module that extends AR"
    end
  end
end

问题

# These work fine....
Autocrat::Job.new # <Autocrat::Job:0x7fd9b017a138>
Autocrat::Job     # Autocrat::Job(id: integer....) < ActiveRecord::Base

#But this doesn't
Autocrat::Job.class_thingy # NoMethodError: undefined method `class_thingy'
Autocrat::Job.new.instance_thingy # NoMethodError: undefined method `instance_thingy'

#it doesn't even see the methods
Autocrat::Job.methods - ActiveRecord::Base.methods # []

问题是我无法访问或调用 Job 类的类或实例方法。我可以很好地实例化 Job,它似乎不知道这些方法存在。

有任何想法吗?

4

0 回答 0