Skip to content

Instantly share code, notes, and snippets.

@codesoda
Created December 1, 2014 18:07
Show Gist options
  • Save codesoda/9cfdd939fa5538e170ce to your computer and use it in GitHub Desktop.
Save codesoda/9cfdd939fa5538e170ce to your computer and use it in GitHub Desktop.
Only On
# Run code only if it's a certain day of the week
# e.g.
# on(:monday) do
# puts "it's monday"
# end
module OnlyOn
def on(day, options = {})
yield if block_given? && day_of_week == day
end
private
def day_of_week
[:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday][Time.now.wday]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment