0

How can I benefit from methods defined in a lib/module in one of my config/initializer?

lib/my_module
----

module MyModule
   def custom_method
      12
   end
end

so that I can use it as follow

config/initializer/random_initializer
----

# following imports do not seem to work
# include MyModule
# require 'my_module'
 
Rails.application.configure do
    config.blabla = custom_method
end

1 Answer 1

1

you could use module_function

# lib/my_module
module MyModule
 def x
  0
 end
 module_function :x
end

# config/initializer/random_initializer
require "my_module"
Rails.application.configure do |config|
 config.blabla = MyModule.x
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.