1

So i have one ruby file that is reside inside model > service

module Services module SomeJobs def mainJob ... end end end 

and 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 

1 Answer 1

1

try this out

module Services module SomeJobs def self.mainJob end end end 

make 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 end 

now call from

outside this TestFunction class like

TestFunction.new.mainJob 

and inside this TestFunction class with

self.class.new.mainJob 

if 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

Sign up to request clarification or add additional context in comments.

4 Comments

I got this error uninitialized constant TestFunction::Services (NameError)
@JitenK does this service module is located in app/models?
this service module located inside app/model/services and this one is extended by one of the model
@JitenK try including it in TestFunction class with 'include ::Services::SomeJobs'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.