Last active
December 16, 2015 08:49
-
-
Save carsontang/5408636 to your computer and use it in GitHub Desktop.
monkey patching Ruby's Time class to include weekday
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
class Time | |
def weekday? | |
days = %w(Monday Tuesday Wednesday Thursday Friday) | |
days.each do |day| | |
return true if __send__("#{day.downcase}?") | |
end | |
false | |
end | |
end | |
if Time.new.weekday? | |
puts "Today is a weekday" | |
else | |
puts "Today is not a weekday" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment