如何写“每个月的第一个Ruby”

时间:2021-10-04 01:08:23

I'm trying to write an iterator in ruby that sends a callback on the first of every month.

我正在尝试用ruby编写一个迭代器,在每个月的第一天发送回调。

How would you write something like that?

你怎么写这样的东西?

2 个解决方案

#1


5  

if Date.today.day == 1
  #do something
end

I'm not sure what you mean by an iterator - i hope you don't mean some program that keeps looping, constantly asking if today is the first day of the month? Sounds like a waste of resources. Use crontab :)

我不知道你说的迭代器是什么意思——我希望你不是指那些不断循环的程序,不停地问今天是不是一个月的第一天?听起来像是在浪费资源。使用crontab:)

#2


2  

if my_date.beginning_of_day == Time.now.beginning_of_month
  my callback
end

#1


5  

if Date.today.day == 1
  #do something
end

I'm not sure what you mean by an iterator - i hope you don't mean some program that keeps looping, constantly asking if today is the first day of the month? Sounds like a waste of resources. Use crontab :)

我不知道你说的迭代器是什么意思——我希望你不是指那些不断循环的程序,不停地问今天是不是一个月的第一天?听起来像是在浪费资源。使用crontab:)

#2


2  

if my_date.beginning_of_day == Time.now.beginning_of_month
  my callback
end