所以我有一个ruby文件驻留在model> service中
module Services module SomeJobs def mainJob ... end end end以及如何从位于lib / testfunction.rb中的ruby类调用该方法
我尝试了以下内容,但没有奏效。 任何帮助是欣赏。 我正在尝试调试代码。
class TestFunction include SomeJobs TestFunction::mainJob endSo i have one ruby file that is reside inside model > service
module Services module SomeJobs def mainJob ... end end endand how do i call that method from ruby class that sit inside lib/testfunction.rb
I tried the following and it did not work. any help is appreciate. I am trying to debug the code.
class TestFunction include SomeJobs TestFunction::mainJob end最满意答案
试试这个
module Services module SomeJobs def self.mainJob end end endmake mainJob是一个模块方法,因为模块实例方法永远不会包含在包含类中,它们对模块是私有的
class TestFunction include Services::SomeJobs end现在打来电话
在这个TestFunction类之外
TestFunction.new.mainJob并且在这个TestFunction类中
self.class.new.mainJob如果你想以类方法的形式访问mainJob,那么使用extend而不是include。
因为您正在使用IDE调试器
尝试要求相对于rails应用程序的文件,在你的
TestFunction类
try this out
module Services module SomeJobs def self.mainJob end end endmake mainJob a module method, as module instance method are never included in the including class, they are private to module
class TestFunction include Services::SomeJobs endnow call from
outside this TestFunction class like
TestFunction.new.mainJoband inside this TestFunction class with
self.class.new.mainJobif you want to access mainJob as class method then, use extend instead of include.
as you are using IDE debugger
try requiring that file relative to rails application, in your
TestFunction Class
更多推荐
发布评论