Rails: I can't call a function in a module in /lib - what am I doing wrong?

前端 未结 9 1750
鱼传尺愫
鱼传尺愫 2021-01-31 08:08

I know I\'m doing something stupid or failing to do something intelligent - I\'m frequently guilty of both.

Here\'s an example of what\'s causing me pain:

I have

9条回答
  •  清酒与你
    2021-01-31 08:23

    You need to prefix your function with the module name because modules are not classes:

    Your /lib/test_functions.rb:

    module TestFunctions
      def TestFunctions.abc
        puts 123
      end
    end
    

    Your code using the module method:

    require 'test_functions'
    TestFunctions.abc
    

提交回复
热议问题