Eloquent Ruby is a book about the Ruby programming language that focuses on Ruby programming style by teaching you how to write your code as a real world hardened Rubyist.
Be prepared, this is an unconventional Ruby book. To use the author’s, Russ Olsen, own words
This is a book about making that final leap, about absorbing the Ruby programming culture, about becoming truly fluent in Ruby.
A formal understanding of the mechanics of Ruby isn’t the same as really looking at the programming world through Ruby-colored glasses. You need to absorb the cultural part of Ruby, to see how real Rubyists use the language to solve problems.
This is something I have been claiming for the last few years. Learning Ruby is not difficult. To start thinking in Ruby and becoming a Rubyist is the real challenge.
The book is divided into 4 parts. Each part is divided into chapters. The book counts 31 chapters and about 400 pages.
- The Basics
- Classes, Modules, and Blocks
- Pulling It All Together
The first part covers some basic Ruby features in a way you normally won’t read in any other Ruby reference. Ah, if I only had the Symbol chapter available when I started learning Ruby!
The second part covers Classes, Modules and Blocks and it explains how to use modules successfully, how to deal with inheritance, equality and operators. This is by far my most favorite section of the book.
The third part is about Metaprogramming. Whilst the name of the section is technically correct, it can be misleading. If you are looking for a complete Ruby and Metaprogramming course, check out Metaprogramming Ruby: Program Like the Ruby Pros . This section covers common Ruby metaprogramming topic such as hooks, method_missing (a must read!) and monkey patching.
The fourth part wraps several topics all together and talks about creating and implementing a DSL in your Ruby applications.
The book ends with a rich list of references of Ruby and programming in general. The list contains amazing Ruby titles like Ruby Best Practices or The Ruby Way: Solutions and Techniques in Ruby Programming, as well programming masterpieces like The Elements of Programming Style. If you’re looking for some inspiration for your next read, you’re likely to find some there.
This book assumes that you have a basic knowledge of the Ruby language. You don’t need to be a Ruby master, but some advanced sections such as Metaprogramming and DSL may require you to stop for a moment and refresh or improve your specific knowledge of Ruby on that topic.
Don’t expect this book to explain the basic details of Ruby or its syntax, this is behind the scope of this publication. There are plenty of commented examples, but if you want to learn about a specific Ruby feature make sure you keep a reference like Programming Ruby 1.9: The Pragmatic Programmers’ Guide or The Ruby Way: Solutions and Techniques in Ruby Programming handy.
Another requirement is that you must be ready to read printed source code: this book is full or Ruby code. At least 50% of the pages contain code, making this book a valuable practical reference.
How was it?
Eloquent Ruby is a very lightweight and pleasant read. The colloquial tone is friendly and engrossing. The book has plenty of code snippets and requires only a few days to read it from beginning to end.
Aside from being an excellent resource to help you get thinking and programming the Ruby way, this book constantly adopts a practical approach providing tons of examples to read. Every chapter ends with an In the Wild section containing examples extracted from real Ruby libraries, and a Wrapping up section that helps you fix the concepts in mind.
I appreciated the focus on tests and the RSpec chapter. Most of the code examples are verified by tests, which are also made available in the book.
I found the Regular Expression chapter pretty boring and misplaced. In fact, it was the only chapter in the book where the main focus was teaching Regular Expression basics, instead of focusing on using Regular Expressions within the scope of the Ruby way.
I would have left the RubyGems section out of the book. There have been several changes in the Gems community in the past couple years and the chapter appears to be slightly outdated.
As a side note, I would have appreciated a wider usage of Ruby 1.9 over 1.8 in order to discourage the adoption of Ruby 1.8.
Who should read it?
If you are a beginner to intermediate level Ruby programmer, this book is a must read that will definitely help you improve your Ruby skill, by writing code the Ruby way.
If you are completely new to Ruby, I don’t recommend this book as a first reading. You might want to start with a Ruby reference to learn about programming in Ruby, then read Eloquent Ruby to learn about programming the Ruby way.
If you are a Ruby expert and you have been writing Ruby for the last 5 years, don’t get over-confident. I’m quite sure the book will be able to provide you some valuable advice more than once.