Ruby Adventures

Part 1: Desugaring

Remember from class that syntactic sugar refers to features of a language’s syntax that make code easier to read and write, but do not provide any additional functionality. Ruby uses a lot of syntactic sugar.

Look at lib/desugaring.rb. The first method, all_the_sugar, contains a tiny snippet of somewhat realistic code from an imaginary web invitation system. (Actual email generation in Ruby on Rails looks very similar to this.)

That snippet of code uses many kinds of syntactic sugar. Your task is to remove the sugar, one step at a time. For each method below, remove implement_me and replace it with the contents of the previous method in the file minus the particular kind of sugar the comment describes.

Please note that the desugaring is cumulative. You should copy the answer for each step forward to the next step, in the order the steps appear in the file. By the end, you should end up with a very different-looking implementation!

You can test that all your desugared versions work correctly by running the project tests, bundle exec rake test. I strongly recommend that you run the tests after each step of the desugaring before copying your code forward to the next step.

When you’re done with this, proceed to part 2.