Ruby on rails - Static method

后端 未结 6 517
青春惊慌失措
青春惊慌失措 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 08:05

    You can use static methods in Ruby like this:

    class MyModel
        def self.do_something
            puts "this is a static method"
        end
    end
    MyModel.do_something  # => "this is a static method"
    MyModel::do_something # => "this is a static method"
    

    Also notice that you're using a wrong naming convention for your method. It should be check_pings instead, but this does not affect if your code works or not, it's just the ruby-style.

提交回复
热议问题