Ruby Practice

You’ve now gotten an introduction to all of the Ruby grammar that you’ll need to build industrial-grade applications. In particular, our next step will be to define classes and inherit from amazingly powerful parent classes that brilliant, generous Ruby developers have shared with the community. This is going to let us build very quickly, without reinventing the wheel. We call this collection of parent classes that we’ll be inherting from “Ruby on Rails”.

However, the more Ruby fluency we have before we get to Rails, the better. So, here are a bunch of puzzles/exercises for you to stretch your legs with. Some things to keep in mind as you are working on them:

  • Try to have a plan (at least for what your first step is) before you start typing.

    The hard part about programming is not writing the code; it’s learning how to think very precisely about solving problems, and breaking your solution down into steps that are so simple that you can tell the computer how to do them.

  • Work in tiny steps. Just try to make something show up, click “run”, and prove that the code you wrote did what you think. If you write 50 lines before you click “run”, it’ll be much harder to debug what went wrong.
  • Make the invisible visible. Use p to see what’s going on, don’t guess.
  • Read. The. Error. Message. And then use it to debug. undefined method? Why? Did you make a typo in the method name? More likely, the object you have is of a class that you are not expecting. Follow it back to where it came from and figure out why.
  • Ask tons of questions on Piazza. Remember that the point of homeworks is to get you to ask questions, i.e. gaps in your mind for knowledge to live.
  • Try to use the information contained in the previous Chapters to MacGuyver a solution to the problem. Try not to Google for a solution; the things you find on Stack Overflow will likely confuse you more than help you.

    There is at least one solution to every puzzle using only methods we’ve covered together.

  • If this page is slow, try clicking the “Open in” link in the top-right corner of each embedded REPL to work on it in a dedicated tab. That ought to be faster.

Here are the challenges1. Good luck! Ask lots of questions on Piazza!

  1. The source of these challenges is the very excellent, a community resource for programming practice and mentorship.