I wanted to spend a bit of time getting familiarized with the built-in Date
and Time
classes, so I decided to build a deadline counter that counted the days left until a given deadline. After requiring Date
and spending some time browsing its methods, I realized it would be easy to create a new deadline date by calling
Date.new
and passing it the arguments year, month, and day. My method turned out to be a lot shorter than I anticipated,
which I think really speaks to the awesome built-ins that Ruby ships with:
Nevertheless I was a bit taken aback by how easy that turned out to be, so I decided to kick it up a notch and write another
deadline counter: student edition! When the clock starts ticking, students don't think in terms of days as much as hours. For that, I needed to rely more on the Time
class. Here it is:
A bit longer, this one! Still, Ruby built-ins made the logic simple. The only extra came
when I realized I needed to create a helper method military
to change hours into military time for the
deadline_hour_counter
method.