Russ Olsen is a long time Ruby coder, speaker and author of Eloquent Ruby and Design Patterns in Ruby. Russ spends his days crafting solutions as an architect at Relevance and his nights on twitter as @russolsen.
A couple of weeks ago I had an opportunity to do one of my very favorite things: I got to explain Ruby to a room full of programmers who knew almost nothing about the language. I've been doing these talks for years and you would think that by now I would be bored with it all, but I'm not. The idea that some of my audience will latch onto Ruby, that it will change their coding life, and that some of the credit will rub off on me never gets old.
Still there is a certain comfortable familiarity to these talks, especially with the questions that people ask: Can you really write reliable programs without static typing? (Answer: Sure!) What happens at compile time and what happens at runtime? (Answer: There is no compile time) Why is zero true? (Answer: Because everything except nil and false are true). One of the hardest questions usually comes at the end of the talk: Where do I go from here?
First Stop: The Internet
The obvious answer whenever you want to learn more is your nearest browser and if it’s Ruby that you are trying to learn then the obvious first stop is the main Ruby language website at www.ruby-lang.org. Go there and you will find downloads of Ruby for various platforms, hints about what is coming in the next release and pointers to other Ruby resources. If you’re a complete Ruby beginner then make sure you have a look at the “Ruby in 20 Minutes” tutorial.
Another great resource for people trying to learn Ruby is the Ruby Koans site. Ruby Koans, which was put together by Jim Weirich and Joe O’Brien, is a series of programming problems designed to get you thinking about the nuances of Ruby coding. The whole thing is done as a mock session with your Ruby Zen master: In the firmly tongue-in-cheek world of Ruby Koans you don’t make your programs work. Instead your code gains enlightenment.
If you are a bit less than a complete beginner or you have simply grown weary of the quest for enlightenment, then take a look at the Ruby Inside blog. Ruby Inside is a nice mix of reviews – both of software and books – along with news of the comings and goings of the Ruby community.
Books for Beginners
As useful as the Internet is, I’m not sure that surfing is ideal for becoming one with a topic as large and as complex as a new programming language. So along with URLs, I usually suggest that new Ruby programmers start with a book. Which book is, however, a difficult question since the answer depends more on the perspective reader than anything else.
For example, if you are a "first things first" kind of person, someone who likes to be very sure of the basics before you move on, then I think that the best book for you is the aptly named Beginning Ruby: From Novice to Professional by Peter Cooper. Cooper starts off with getting Ruby installed on your computer and then takes you through the basics and some not-so-basic aspects of Ruby. Cooper (who is also the evil genius behind the Ruby Inside blog) writes in a pleasant conversational style and he has a good sense of pacing – not too boringly slow, not too confusingly fast. Do try to get hold of the second edition, since it covers the current version of Ruby (1.9). Also, keep in mind that the aim of this book is to teach you Ruby – it's not a reference. And don't take the "Novice to Professional" part of the title too seriously. Beginning Ruby does a great job of getting the Ruby newcomer off the ground, but "Novice to Professional" is probably more than any one book can manage.
Alternatively, you could go with the classic: Programming Ruby 1.9 by Thomas, Fowler and Hunt. Known to Ruby programmers as the “pickax” book after the illustration on the cover, Programming Ruby 1.9 is the book that taught the first couple waves of Rails programmers the language. If you were only going to buy a single Ruby book, this would be it. Dave Thomas and his co-authors go about the business of being all things to all Ruby programmers by writing a multi-pass book: The first quarter of Programming Ruby 1.9 is a quick tutorial introduction to Ruby. This is followed by a much more in-depth look at the language and its supporting ecosystem. The final (very large) bit of the book is a class by class, method by method reference to the standard Ruby library. The pickax book tries to do it all, but as a tutorial it just didn’t work for me. There is something about its multi-pass approach to learning that my brain just doesn't like. But that's just me -- many of my fellow Rubyists swear by it. It all comes down to you and your learning style: If you learn better by getting the general idea first and then digging deeper, then Programming Ruby 1.9 just might be the book for you.
The third candidate for your first Ruby book is David Black's The Well-Grounded Rubyist. In many ways The Well-Grounded Rubyist resembles Beginning Ruby: Both explain Ruby bit by bit in a single pass. The difference is depth. Beginning Ruby does a great job of balancing the level of detail with the need to keep moving. By contrast, The Well-Grounded Rubyist goes for thoroughness. Every time David Black takes the covers off of a new part of Ruby, he is going to explain every last wire and gear before he moves on. If that strikes you as the “right” way to learn, then by all means get yourself a copy of this excellent book.
Just Beyond Beginner
I have to admit that I'm a little biased about which Ruby book you should read second: I would suggest my own Eloquent Ruby. In my defense, let me say that I wrote Eloquent Ruby especially as a second Ruby book. The goal of Eloquent Ruby is to explain how Ruby is used in the real world, to provide recently arrived Ruby immigrants with a guide to how to use the language. I'm not just talking about style here: While there is plenty of advice in Eloquent Ruby about how to indent and where to leave out the parentheses, a lot of the book is devoted to getting the most programming miles out of features like code blocks and metaprogramming. Eloquent Ruby also reflects my view that one of the best ways to get beyond the basics of any programming language is to look at real code from real applications, so mixed in with all the sage advice is lots of examples from the Ruby standard library and Rails.
I'm also biased about Ruby Best Practices, but not because I wrote it: Gregory Brown did. I just wish that I wrote it. Ruby Best Practices, which is available free at http://rubybestpractices.com, is like that senior developer who sits you down and shows you how to really do things on the project. There are chapters on doing test first development, on internationalization, on building gems and even on debugging. Although some of the details are a bit dated, it is still well worth your time.
One other book that every advancing Ruby programmer should own comes right from the source: The Ruby Programming Language is by David Flanagan and the man, Ruby inventor Yukihiro Matsumoto. A quick glance at the table of contents might lead you to believe that The Ruby Programming Language is another tutorial along the lines of Beginning Ruby or The Well-Grounded Rubyist. It's not. The Ruby Programming Language is a statement of how Ruby works. There is no coddling of beginners here: The first chapter, entitled "Introduction" is topped off with a six page example program. The rest of the book is a step by step examination of the in's and out's of Ruby. This is the book that I turn to when, for example, I need to know how constant look-up works or what the proc method returns this week.
Way Beyond Beginner
Congratulations! You've worked your way through the fundamentals and now you're ready to dig deeper. One way to do that is to get hold of a copy of Hal Fulton's The Ruby Way. The Ruby Way pretends to be a cookbook – here's a programming problem, and here's how you deal with it – but in fact it is a step by step manual on how to approach coding the Ruby way. Be aware that the current edition (the second) is getting a bit dated but a third edition is in the pipeline.
If you find you are suffering from the “all my Ruby code looks just like my Java code” problem let me suggest – while turning the bias warning light on again – my own Design Patterns in Ruby. Design Patterns in Ruby looks at 14 of the traditional GoF design patterns and recasts them into real Ruby solutions.
Now a lot of those real ruby solutions involve metaprogramming, so if you have gotten this far and metaprogramming still seems like a black art, you might want to take a look at Paolo Perrotta's Metaprogramming Ruby: Program Like the Ruby Pros. Perrotta has produced a solid book about a topic with which many new Ruby coders struggle. Do be aware that Metaprogramming Ruby relies on a sort of coding soap opera to carry the plot along:
Bill is right there with you, verbalizing precisely what’s going through your head: “This is just the same method again and again, with some minor changes.” You turn to each other and ask simultaneously, as if on cue, “How can we refactor it?”
People tend to either love or hate this sort of thing, so think about which category you fall into before you hit "Buy It Now."
Another book to consider as you lose your Ruby amateur status is The RSpec Book by Chelimsky, Astels, Dennis, Hellesøy, Helmkamp, and North. Along with having enough authors to fill out a basketball team (complete with coach), the RSpec Book is actually two books in one. The first third is an explanation of, and a passionate argument for, behavior driven development. The rest of the book is a detailed explanation of two of the Ruby world's favorite test tools, RSpec and Cucumber. Both bits of The RSpec Book are worth reading and together they are a compelling combination.
So there you have it: Ten books and a handful of web sites to get your Ruby career off of “hello world.” Of course many – perhaps most – of you are interested in Ruby because it is the underpinnings of Rails. There are lots of ways to learn about Rails... But that’s an article for another day.