Skip to content

Instantly share code, notes, and snippets.

@norman
Created April 10, 2013 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norman/5354944 to your computer and use it in GitHub Desktop.
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.
# 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