Trip
Trip

Reputation: 27114

How to write "First of every month in Ruby"

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

How would you write something like that?

Upvotes: 2

Views: 507

Answers (2)

Max Williams
Max Williams

Reputation: 32943

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 :)

Upvotes: 5

shingara
shingara

Reputation: 46914

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

Upvotes: 2

Related Questions