Ruby on rails - Static method

后端 未结 6 498
青春惊慌失措
青春惊慌失措 2020-12-09 07:31

I want a method to be executed every 5 minutes, I implemented whenever for ruby (cron). But it does not work. I think my method is not accessible. The method I want to exec

6条回答
  •  时光取名叫无心
    2020-12-09 07:56

    Instead of extending self for the whole class, you can create a block that extends from self and define your static methods inside.

    you would do something like this :

    class << self
    #define static methods here
    end
    

    So in your example, you would do something like this :

    class Ping
      class << self
        def checkPings
          #do you ping code here
          # checkPings is a static method
        end
      end
    end
    

    and you can call it as follows : Ping.checkPings

提交回复
热议问题