Chapter 11 - Documentation

Exercise 1: Looking up docs for a Ruby core class

Write a program to print the current date in the format below.

Today is Thursday, April 14, 2016

Use the Ruby core class Time. Here’s the catch: we don’t cover the Time class anywhere in the book. You’ll need to look up documentation on Time yourself.

Some hints:

  • You’ll need to call a class method to get an object representing the current date and time.
  • You’ll call instance methods on that object to get the day of week, month, day of month, and year.
  • You’ll get the day of the week back as a number. You’ll need to build an array or hash that can help you convert it to a string.
  • The month will also come back as a number. Build a hash to help you convert it to a string.
  • Interpolate all these values into a string to get the correct format.

When you’re ready, have a look at our solution.