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

前端 未结 9 1756
鱼传尺愫
鱼传尺愫 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:20

    You can also use module_function like so:

    module TestFunctions
      def abc
        puts 123
      end
    
      module_function :abc
    end
    
    TestFunctions.abc  # => 123
    

    Now you can include TestFunctions in class and call "abc" from within TestFunctions module.

提交回复
热议问题