I don't like being negative on Ruby Inside without good reason. Trivia like DHH's test library preferences can provide a fun talking point but pointing out specific flaws in someone's work is rarely insightful.
I wasn't going to publish a review of this book but when I discussed the issues with people on IRC, Twitter and e-mail (to find second opinions), I was pressed to push on, primarily to serve as a warning to newcomers who may pick up this book. So, let's tread carefully..
What is The Book of Ruby?The Book of Ruby is a new Ruby book published by No Starch (who, as a publisher, I love - The Linux Programming Interface is one of the best books I've ever read) and written by Huw Collingbourne. It came out this month (July 2011) and is available in print and e-book formats as well as on the Safari Books subscription site.
While other books focus on Ruby's trendier features, The Book of Ruby reveals the secret inner workings of one of the world's most popular programming languages, teaching you to write clear, maintainable code.
Sales page for TBOR
This book was spawned from a freely available PDF Huw wrote in 2009, also called The Book of Ruby. (Notably, it's included with the Windows-based RubyInstaller.) But you can't just follow along with this review using the free PDF since it has been rewritten, tech-reviewed (supposedly by Pat Eyler) and includes fresh stuff on Ruby 1.9 and Rails 3. The TOC remains similar, nonetheless.
Who's Huw?Huw's main claim to fame is as author of Ruby In Steel, an awesome Ruby development environment for MS Visual Studio. I've promoted it several times in the past (Update: Given Huw's personal attacks in response to this review, I am no longer doing so - you will need to Google it for yourself.)
Despite what I say about the book, I have nothing against Huw (having only traded a few e-mails) and have admired his work from afar. I can't believe how he gets so much done with his Visual Studio extensions.
So, The Actual ReviewFirst impression: Huw writes well. He doesn't waste time and he's never "dry." He demonstrates a solid interest in Ruby and proceeds at a good pace through a wide selection of topics that'll be of interest to both Ruby newbies and more advanced developers.
Sometimes the coverage is a bit shallow. Despite the first chapter being called "Strings, Numbers, Classes, and Objects" — a pretty wide range of topics — it lasts a mere 13 pages. The "Numbers" section is 3 paragraphs long. This struck me as odd for a book whose sales blurb says: "The Book of Ruby reveals the secret inner workings of one of the world's most popular programming languages"
The book is interesting as something to browse through or if you're an experienced developer from another language who's OK with learning one (frequently non-standard) way of doing something in Ruby. Huw moves quickly and frequently probes into some interesting elements of syntax and underlying language functionality on the way (mostly in the Dig Deeper sections at the end of each chapter - a nice touch).
Some chapters are notably strong and dig into some curious crevices. The chapters on Symbols, YAML (which rarely gets much coverage in other books), Marshal (ditto), Threads, and Conditional Statements are solid and you'll pick up some interesting tidbits. Little more than you'd pick up from The Ruby Programming Language or the Pickaxe, though.
At other points, things get a bit confused:

This is the first time I've read a book that claims to delve into "secret inner workings" where the author admits that they don't know the answer to a verifiable and straightforward problem. While he says that I can't get Ruby to tell me, Ruby can do so (this will work straight-off on MRI Ruby 1.9):
require 'ripper'; require 'pp'; pp Ripper::SexpBuilder.new("puts{}.class").parse
(A note for the intrigued reader: {} is being treated as a block being passed to puts. puts returns nil and then class is being called on that.)
Despite the odd confusing moment, though, the key issue with this book doesn't ultimately lie in the author's writing style or even his approach (which varies from fair to great, depending on the chapter). The main problems orient themselves around something more important than all of that..
Inconsistent Code and StyleThe code in the book is inconsistent not only in regard to established Ruby style but from page to page of the book itself. It jumps between conventions even on basic issues (this is only scratching the surface):
puts 'hello world' # on page 1
puts( "Hello #{name}" ) # on page 2
puts(Class.to_s) # on page 12
abc(a, b, c ){ puts "four" } # on page 166
The author makes a point on several occasions about how parentheses reduce ambiguity in the code, but if you like Lisp you'll love this book because there are parentheses almost everywhere. Except.. when they seem to get forgotten. You'll see one code sample full of them in a particularly un-Rubyish fashion and on the next page with none. Odd.
Similarly, the code has wandering indentation (even within single code examples). Rather than the 2 spaces to which Rubyists are most accustomed, the book uses 4 spaces. Sometimes 2. And sometimes 6. Actually, just pick a number between 1 and 6:

Also be prepared to get almost no grounding on variable or method naming conventions. The author isn't keen on them and instead switches between snake_case, allinasinglewordcase and CamelCase on a whim.
When challenged on some of these issues elsewhere (notably on Reddit), the author pointed to an article he wrote called Programming With Style in which he said:
So, when I switch from one programming language to another do I change my coding style to fit the language? The answer is: up to a point. Or, to put it another way: as little as possible.
Huw Collingbourne
It's no surprise, then, that the style in this book is not only un-Rubyish but that it's not even consistent to any other language, it's a mishmash of Smalltalk, Java, C, and some odd language that has no consistency in indentation. Chad Perrin wrote an article about the issue in response to Huw's comments.
Chad sagely notes:
I may disagree with Huw Collingbourne's choice of coding style, but do not much care if he uses it for his own private purposes. I just care that he replaces idiomatic style in a book designed to impress good programming practice on new students of the Ruby language.
Chad Perrin
And Just Plain Weird Stuff™Some things in The Book of Ruby are just weird.
The author is not keen on do .. end for multi-line blocks and inconsistently drags out the curly brace form (usually reserved for one-liners) in most cases. Coupled to that, he frequently doesn't like putting block arguments on the same line as the start of the block either. This leads to rather unusual looking constructs. I have to show you an example. I've taken a screenshot of the book just in case you don't believe me (this is from page 173):

Any competent Rubyist could understand this code but, and I know I'm not the only one here, seeing this sort of thing quickly leads to thoughts of "Who wrote this!?" and "What's the deal here?" Style is not solely an anally-retentive attempt to get everyone writing the same way. It's also a way to recognize who follows reasonable conventions and an indicator (like it or not) that can cause us to form a prejudiced opinion about someone's overall competence. This is as much true with programming languages as with spoken language.
Again:

I'm not in the mood to trawl through the entire book picking it apart, but any experienced Rubyist will find a lot of nits to pick, including:
- The term 'interpolation' is never mentioned. It's introduced as 'embedded evaluation' and referred to as 'embedded' code throughout the book.
- The
%warray creation technique is explained as being "unquoted text separated by spaces between parentheses preceded by %w", although parentheses, in particular, aren't mandatory at all. - Extra
thens onifs all over the place. But not always. Just sometimes. - The "Iterating over Arrays" section explains one way to iterate over an array: the
for .. in ..loop. - An attempt is made to see if an object has a singleton method called "congratulate" by using
item.singleton_methods.include?("congratulate")- this won't work in Ruby 1.9 sincesingleton_methodsreturns an array of symbols, not strings. This matter is only cleaned up 2 pages after it's used.
Many code examples are a little odd or inconsistent even given the context of the writing surrounding them. Just a handful:

Chad Perrin talks about this more in his review of what he calls The Book of Weird Ruby.
Who Should Buy It?If you're an intermediate or expert Rubyist, you're probably going to pick up or be reminded of something useful, so it might help fill a few holes in your knowledge. It might also act as a grim reminder of why teaching and maintaining a consistent style is important.
If you're a total Ruby newbie, I think you'll learn too many bad habits from this book for me to recommend it with any sincerity. If you're still interested though, you'll already need to know what things like variables, methods and strings are (all are mentioned on the first page without any explanations) so it's not for total programming newbies. If you're willing to ignore the book on matters of style, give it a try, there's enough interesting stuff to see.. but you could just as easily read Eloquent Ruby instead and pick up things on both angles.
The ChaptersHere's a brief outline of the main contents (you can get a deeper look in this PDF):
- Strings, Numbers, Classes, and Objects
- Class Hierarchies, Attributes, and Class Variables
- Strings and Ranges
- Arrays and Hashes
- Loops and Iterators
- Conditional Statements
- Methods
- Passing Arguments and Returning Values
- Exception Handling
- Blocks, Procs, and Lambdas
- Symbols
- Modules and Mixins
- Files and IO
- YAML
- Marshal
- Regular Expressions
- Threads
- Debugging and Testing
- Ruby on Rails
- Dynamic Programming
It's pleasant to read Huw's writing. He panders to the reader just the right amount and strikes a good balance between being over-familiar and dull. You'll enjoy his explanations and find his pacing pleasant for the most part, even if the depth isn't always there. As Steve Klabnik said on a ruby-talk discussion about the book:
I've actually read the book (admittedly skimmed in parts), and it's a fine book, with one exception: The author uses a very non-standard
coding style. You can see it in the example chapter. So, good for learning, except no Ruby code you ever read will look like that.
Steve Klabnik
What kills the book, however, is its disregard for code consistency and long-standing Ruby style conventions. More worryingly, the author knows this and seems not to care. Tab-sizes jump from 4 to 6 and back again, there's bad spacing all over the place, there's no consistency with variable name formatting or the use of parentheses, and, in general, the style used is little like any Ruby code I've come across before (and I'm reviewing and code-walking Ruby code from hundreds of developers on a regular basis). If you learnt Ruby only from this book, you'd pick up a lot of bad habits to correct. I can't believe for a minute that the named tech reviewer, Pat Eyler (a stand up guy in the Ruby world), signed off on all of this without a fight.
Another comment from Reddit:
When learning a new language we apply the idioms of what we know best from our past into this new language until we've learned the new language well enough to be fluent and use it's own idioms. However, I don't think any of us(except you Huw) would be so bold as to write a book half way through this process, having given up on learning idiomatic ruby and attempting to convince the rest of the world that your way is the best way.
crassnlewd
This is the first No Starch book that has given me any doubts about their editorial process and I hope it's a mere aberration. The last two books I read from them, Eloquent JavaScript and The Linux Programming Interface seriously impressed me and continued the positive impression I'd formed over the years.
Usually this is where I'd link to ways to get the book. I'm not going to elaborate on this, however, as I don't want to profit from it. Google "The Book of Ruby" or find the link to No Starch's product page at the start of this review if you want to grab a copy.
Lately, if you think this review is missing the mark, feel free to leave a comment or head over to Chad Perrin's review which provides a slightly different take.
Over at the always-riveting official Ruby blog, Shota Fukumori
The Ruby and Rails job scene continues to grow through 2011 and we've got *drumroll* 13 (lucky for some) jobs to share from the
Amazon has unveiled 
Ruby Inside wouldn't be what it is without you but it's time for me to thank the companies who also help to keep Ruby Inside going by sponsoring my work. Thanks!



