There’s no denying the stir that Ruby on Rails has caused in the web development community. Since its release in 2004, it has gained a rapidly expanding user-base through its lightweight, elegant code, and marked benefits for productivity. It has also raised the profile of Ruby itself, the dynamic, object-oriented scripting language first released in 1995 by Yukihiro “Matz” Matsumoto. Ruby has been hugely popular in its homeland of Japan for a long while, but only began to gain popularity in the West in the last six years.
So not only are users coming new to Rails, but also to Ruby itself. David Black’s Ruby for Rails aims itself squarely at that sizable audience. It is not so much a book about “Ruby specifically for Rails” as one about “Ruby for people who have come to it through Rails”. Whilst many Rails users quickly get their heads around its clean-cut, minimal syntax, the first problem they often run into is Ruby itself. Ruby is a highly idiomatic language, and does not resemble the C-like languages most people are familiar with. Given the ever-increasing popularity of Rails, this book could not have been published at a better time.
The book takes the form not of a reference, but a linear tutorial. The first handful of chapters look, in turn, at the very basics of writing and running Ruby scripts (along with a quick guide to the Ruby command-line interpreter), the very basics of getting a Rails app up and running, and concludes with a look at beginning to use simple Ruby scripting techniques to enhance you application.
The book then takes a marked turn away from Rails, and concentrates on getting down to the nitty-gritty of Ruby itself. These chapters are the real highlight of the book – not for the keywords and methods they teach, but for the way in which they explain Ruby’s core and abstract concepts. Ruby’s real strengths – its highly dynamic nature and complete object orientation – are potentially its most confusing concepts, and yet Black’s methodical, plainly-written approach lays their complexities bare. His explanations of Objects, Classes, Modules, and how inheritance works are probably the best I’ve seen yet for Ruby, and coupled with an excellent chapter solely devoted to scope and
self (the default object), get the complex underpinnings of the language out of the way in a very accessible style. (The sample chapter, on the basics of objects and classes, should give you a feel for Black’s clear, authoritative tone).
After that, the book moves on to cover control flow, devoting a good number of pages to the key concept that is code blocks, and then some slightly less complex chapters cover variables, scalars (strings, numbers, and symbols), collections (arrays and hashes) and regular expressions; these share more in common with languages the reader may be more familiar with. Still, just like the very first introductory chapters, they are all worth reading to the end – whilst they may start with common concepts, by the end, every chapter touches on the aspects that make Ruby unique, and explains some of the deeper complexities.
The Ruby language section ends with another fine, complex chapter, looking at Ruby’s capabilities as a dynamic language. In this chapter, as well as getting a handle on some really idiomatic Ruby concepts, the ‘magic’ present in Rails really starts to fall into place. Throughout the language-oriented chapters, Black always refers back to concepts within Rails, often in ActiveRecord, using what has just been learned to explain the more ‘magical’ aspects of Rails.
With the language-focused chapters out of the way, Black returns to the Rails app he began at the very beginning, and enhances it with the Ruby skills we’ve learned throughout the book. It’s here that a great deal falls into place – not just from a greater appreciation of what’s going on under the hood, but also through a new-found appreciation for Ruby idiom, and how best to work with (rather than against) Rails.
If there are faults with the book, they are few. Black consistently gives his example database schemas as SQL. Whilst I have no problem with this personally, it’s becoming more common in the Rails community to list them as database-agnostic Ruby migrations. Also, some of the code examples in the book may seem a little confusing to begin with – one early example features a lambda function, a concept not really explained until a good few hundred page later. And the initial chapter on Rails seems perhaps a little rushed, trying to cover much of the ground that many may have read in Agile Web Development with Rails.
But these are minor gripes. Ruby for Rails is an excellent guide to the Ruby language, especially for anyone coming to it afresh. It’s exactly the book that many in the Rails community have been waiting for, and it’ll improve your pure Ruby skills no-end. Certainly a book that I’ll be returning to many times in the future.
- Title: Ruby for Rails
- Author: David Black
- URL: http://www.manning.com/black/
- Price: $44.95 Buy Ruby for Rails at Amazon and save $15
- Rating out of 5: 4