所以我正在编写一个包含多个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,它似乎并不知道方法存在。
有什么想法吗?