2013-07-31 92 views
1

,所以我有一个红宝石文件,它是位于内部模型>服务调用模块方法

module Services 

    module SomeJobs 


    def mainJob 
    ... 
    end 
    end 
end 

,我如何调用从Ruby类方法是坐的lib/testfunction.rb内

我尝试以下,并没有奏效。任何帮助是欣赏。我正在尝试调试代码。

class TestFunction 
    include SomeJobs 

    TestFunction::mainJob 
end 

回答

0

尝试了这一点

module Services  
    module SomeJobs  
    def self.mainJob 
    end 
    end 
end 

使mainJob一个模块的方法,如模块实例方法不会被包含在包括类,它们是私有模块

class TestFunction 
    include Services::SomeJobs 
end 

现在从调用

这TestFunction类外

TestFunction.new.mainJob 

这TestFunction类中有

self.class.new.mainJob 
如果您要访问mainJob作为类的方法,然后,用延长的,而不是包括

与您使用IDE调试

试要求相对该文件的Rails应用程序,在你的

TestFunction类

+0

我得到这个错误 未初始化的常量TestFunction ::服务(NameError) – jimagic

+0

@ JitenK这个服务模块位于app/models中吗? –

+0

这个服务模块位于应用程序/模型/服务和这一个扩展的模型 – jimagic