Nithin Bekal

Posts About Notes Slides

Review: Eloquent Ruby (Russ Olsen)

28 Feb 2011

If you are new to Ruby programming, Eloquent Ruby should be the book you read right after you finish your introductory Ruby book. It’s not a beginner’s tutorial, but with a little background on Ruby, it would be easy to follow.

This is one of the better programming books I’ve read. It has plenty of short and clear example code snippets, a very conversational and humorous writing style and most importantly, covers exactly the kind of topics a newbie should understand about Ruby.

The book is divided into 4 parts - (1) The Basics, (2) Classes, Modules and Blocks, (3) Metaprogramming (4) Pulling It All Together.

The firsts section covers the basic Ruby idioms in a way that you wouldn’t normally get to read in most books. It has chapters like “Choosing the Right Control Structure”, “Write Specs”, “Embrace Dynamic Typing”.

The second section – the most useful one, in my opinion – covers classes, modules and blocks with chapters like “Use Class Instance Variables”, “Use Blocks to Iterate” and “Use Modules as Name Spaces”. This section does an excellent job of explaining how to effectively use blocks, which are probably Ruby’s most useful feature.

The third section talks quite a lot about using, and of not misusing, the powerful method_missing method. Other Ruby metaprogramming topics such as monkey-patching are also covered.

The final section talks about one of Ruby’s greatest strengths – building DSLs – and also about creating and packaging gems. The book wraps up with a quick note on the the available ruby implementations.

At the end of each chapter there is a section “In the Wild” where the author points to real world code relevant to that chapter. Knowing where to look for real world examples will be especially useful for newbies who haven’t read a lot of other people’s code.

Another useful section in each chapter is “Staying Out of Trouble”, where the author explains the common pitfalls associated with the topic being discussed.

The examples that are used in the book make it extremely easy to understand. I often find books choosing overly elaborate examples and thereby distracting readers away from the language idiom being discussed. Eloquent Ruby doesn’t have that problem. The author starts with a simple Document class and uses the same example throughout the book, making it easy to focus on the idiom being discussed.

There are no real negatives I can point out, except for the slightly outdated chapter on packaging gems. However, I was reading the Safari’s Rough Cuts edition of the book, and it’s a work in progress, so it might get updated soon enough.

This book is a must read if you are a beginner to intermediate level Ruby programmer. It teaches the Ruby way of writing code, and answers many of the questions that one might have on the effective use of Ruby idioms.

You can read the Rough Cuts edition on Safari Books online.

Hi, I’m Nithin Bekal, a software craftsman with over 7 years of experience in shipping web applications. I mostly use Ruby, but lately have also been exploring Elixir. Co-founder of CrowdStudio.in, and helping organize Rubyconf India. Tweet to me at @nithinbekal.