Pages

01 September 2006

Ruby Quizzzzzzz

After 3 weeks of vacations (a wonderful place in Greece), I felt I needed some kind of warm-up,...

So I undertook the idea to answer the week's quiz from the RubyQuiz site every week.

This week quiz was especially fine since it was also simple enough to be used as an introduction to Ruby for our weekly Dojo at work (see here and here).

The subject of the quiz is to have a class that's able to transform days of the week into a human compact format:
  • [1, 4, 6] should be displayed 'Mon, Thu, Sat'
  • ['Monday', 'Tuesday', 'Wednesday', 'Thrusday', 'Sunday'] should be displayed 'Mon-Thu, Sun'
This looks simple but may be tricky to write properly,...

It was very interesting to take a look at the other submissions after coming up with my own solution:
  • I discovered there was a way to use the Date class to get standard day names
  • You can use infernals text manipulation ideas to get the job done (short but unreadable to me)
  • No one used Sets or extended the Range class like I did
  • There were only few submissions creating ranges from an array with successive integers in a readable way (this is were I struggled the most)
  • Not everybody submitted unit tests
  • I was the only one to submit specifications using rspec
  • After writing down my own solution, I just modified it to take advantage from the "inject" method of Enumerable to make my code more concise
Well, I look forward for doing the next quiz, or even best,... submit a quiz myself!

No comments: