Skip to content

Instantly share code, notes, and snippets.

@carsontang
Last active December 16, 2015 08:49
Show Gist options
  • Save carsontang/5408636 to your computer and use it in GitHub Desktop.
Save carsontang/5408636 to your computer and use it in GitHub Desktop.
monkey patching Ruby's Time class to include weekday
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