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

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

    If you want Module-level functions, define them in any of these ways:

    module Foo
      def self.method_one
      end
    
      def Foo.method_two
      end
    
      class << self
        def method_three
        end
      end
    end
    

    All of these ways will make the methods available as Foo.method_one or Foo::method_one etc

    As other people have mentioned, instance methods in Modules are the methods which are available in places where you've included the Module

提交回复
热议问题