Created
April 10, 2013 14:07
-
-
Save norman/5354944 to your computer and use it in GitHub Desktop.
My code before and after reading the docs for Ruby's Date class from stdlib.
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
# before | |
class Date | |
def first_business_day_of_month | |
date = beginning_of_month | |
loop do | |
return date if date.workday? | |
date = date.next | |
end | |
end | |
end | |
# after | |
class Date | |
def first_business_day_of_month | |
beginning_of_month.step(end_of_month).detect(&:workday?) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment