Created
December 1, 2014 18:07
-
-
Save codesoda/9cfdd939fa5538e170ce to your computer and use it in GitHub Desktop.
Only On
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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