by Lucas Carlson and Leonard Richardson
I also have to admit to loving the O’Reilly “Cookbook” series. Several, particularly the “Perl Cookbook”, have pride of place on the bookshelf closest to my computer. So the “Ruby Cookbook” by Lucas Carlson and Leonard Richardson was eagerly awaited. The “Cookbook” series are designed to provide you with a plethora of code examples to guide you in writing your own code. I’m definitely a hands-on style of learner and the Cookbook series suits my style – I can start getting my hands dirty with complex problems knowing I have help to code my way of out of the tight spots. This one covers a wide range of tasks from simple, such as walking a directory tree or manipulating text and numbers, through to more complex such as working with AJAX in Ruby on Rails. If you have’t previously come across a book in this style then each chapter is broken up into a number of ‘recipes’ with a problem, a solution and then discussion of the solution.
This sort of book lives and dies by two criteria – the quality of the code and the usefulness of the recipe selection. “Ruby Cookbook” wins on both. The topics covered are wide and leave little, if any, part of the language unexplained. They start with data and structures such as strings and hashes before moving on to code blocks, objects, classes and modules. There is then an intriguing chapter on reflection and metaprogramming that I am still puzzling through before the book moves on to more internet based topics such as XML, HTML, web and internet services and, of course, Rails. The book then proceeds with chapters on the necessary housekeeping of development such as testing, packaging and automating tasks with Rake before finishing with extending Ruby with other languages and system administration tasks. The code is well written; clear and well commented, easily understandable by a virtual newb like me. The discussion is fairly clear, seemingly concise while allowing you to understand the code and how it might be changed for particular purposes.
I’m not going to go into more details as to the contents but instead point you to the book’s page at O’Reilly which includes a link to the contents, listnig all the recipes in the book, and two example chapters; Chapter 7 on code blocks and iteration and Chapter 15 devoted to Rails. Together they will give you a good feel for the style and contents of the book.
The book is well written and well edited. I’ve already tried over a dozen of the recipes and haven’t found a single code error, so my faith in the other 300 or so has risen considerably. The discussion that accompanies each recipe is a marvelous way of learning just that little bit more about the language. I found them quite good, though the odd one could do with further explanation if the book is to stand on its own – for example the discussion accompanying the recipe to iterate over a hash was not perfectly clear on the difference between Hash#each and Hash#each_pair.
At more than 800 pages this is a large and extensive volume, though the price may make you wince. Usually programming books this large have at least part of their size dedicated to something I refer to as pseudo-padding, some sort of reference or simple language explanation – this one has neither, all of it is devoted to the recipes.
With Ruby use, thanks in no part to the popularity of Rails, growing by leaps and bounds I’m sure this volume will be a well deserved bestseller. I give it an eight out of ten and recommend it to all but the most expert Ruby programmers. For beginners who, like me, appreciate hands on learning it is a must.