Ruby quiz (easy) #5

question mark

Question

Monkeypatch the Time class by adding a next_business_day method, which takes the amount of business days as a parameter.

Note: the active_support gem will be helpful for ‘navigating’ days, e.g. Time.now.tomorrow

To make things clear, this test case should pass:

Solution

Thoughts

  • Say you want to find the 1000th business day, it is not optimal to call Time#tomorrow more than 1000 times. Optimization on that one might fit another quiz question of a harder difficulty level!
  • Introductory article about ‘telling time in Ruby’, where the chronic gem is mentioned, which allows you do to stuff like Chronic.parse('3 months ago this friday at 3:45pm')
Advertisements

Got a comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: