Learning Ruby

Knowing where to start

Written by Eric Strathmeyer.

When I was an undergrad studying computer science, I thought I’d eventually settle on a single programming language, gain mastery, and use that language for the rest of my career. I couldn’t have been more wrong. It seems like I learn a new language every couple of years. When I joined Square two years ago, I learned Ruby — and I’m still learning more about it everyday.

Recently, a new employee reached out to our Rubyists mailing list and asked for advice on how to start learning Ruby. After writing my reply, I realized it was general enough advice that it would be useful for any beginning Rubyist. So, we’re sharing it here on The Corner.

As I see it, there are different aspects to Ruby mastery:

  1. Learning the basic syntax

  2. Learning the colloquialisms, like foo.map(&:bar)

  3. Learning how to use Ruby’s OO facilities for good rather than evil

For #1, I used David Black’s Well Grounded Rubyist. I often find intro books are too vague, but I enjoyed the level of education the book provided. It went into enough detail to satisfy my curiosity, while sometimes telling me, “For your own good, ignore this until later.”

For #2, I just had to read/write a bunch of code. I read Well Grounded Rubyist prior to joining Square, so I had a handle on the basic syntax — but that didn’t get me very far. My first few months were spent learning Ruby conventions, the standard library, and the Rails API. I learned an incredible amount from my colleagues through our frequent code reviews and by reading Ruby’s docs when I had a specific question. The Enumerable Module doc is worth reading in its entirety. I use those methods daily.

For #3, I highly recommend Sandi Metz’s Practical Object Oriented Ruby. I’m a huge fan of Sandi. In the book and in her talks, she uses examples that are complicated enough to demonstrate the principle in a non-trivial way, yet general enough that I can apply the lesson to my own code. Don’t think that you have to have mastered #1 and #2 before trying this book. In fact, you might try starting with this book, and then use other books to understand why the code is behaving as it does.

If you’re looking for a quick intro into Sandi’s genius, check out this 40-minute video where she refactors a huge, ugly if statement into small testable objects: All the Little Things. She specifically highlights that initial refactoring efforts can actually increase complexity in the short term and junior developers have trouble seeing the light at the end of the refactoring tunnel.

Rails and Rspec use Ruby’s meta-programming features to construct domain-specific languages. I recommend that you do not try to learn those DSLs from top to bottom. You’ll pick them up quickly enough while you’re doing your job. I would however recommend trying to figure out whether a given bit of magic is provided by Ruby, Rails, or Rspec (or some other gem). Then, if you want to use the #present? method in a Sinatra app some day, you’ll know how to import it.

Of course one of the best ways to learn is to ask a friendly coworker! Eric Strathmeyer - Profile software engineer @Squaremedium.com