For the last couple of months I've been working with Rails 3 in my spare time. Generally I've been productive, despite my lack of Ruby knowledge. Lately I've reached a point where I need a better understanding of Ruby to dive deeper into the Rails code and figure out how the magic is implemented.
I've been programming for years with static languages like C++ C# so I went looking for a book that introduces Ruby without being an introduction to programming in general. I started reading "The Ruby Programming Language" by David Flanagan and Yukihiro Matsumoto. Despite the positive reviews, I found the book a bit dry and gave up a couple of chapters in. To be fair, the intent of this book is to be more of an authoritative reference and less of an language introduction.
Next I started reading David A. Black's book "The Well-Grounded Rubyist" and didn't look back. The layout of the book is its greatest strength, making it easy to learn the language without being overwhelmed with details. It is divided into three parts, each progressively with more detail and longer code samples. The first part is a broad but shallow into the language and the environment: objects, classes, and modules. The second part circles back and gives more information on built-in classes: strings, collections, file I/O, regular expressions. The third part layers on the dynamic aspects of Ruby: object individualization, callable and runnable objects, callbacks, hooks, runnable objects.
Experienced developers new to Ruby will find the first part interesting and useful. The second part on built-in classes is tedious in some sections; however, the text is easy to skim, allowing the reader to focus on concepts more unique to Ruby like bang (!) methods, symbols, the enumerable module.
The third part is where the book really shines. The code samples are
short but carefully chosen to showcase the power of Ruby.
BasicObject is combined with
method_missing to allow formatting of
lists, in the spirit of the Builder library by Jim Weirich.
socket module is combined with threads to write a networked
rock-paper-scissors game. Hooks provided by Ruby (such as
method_added) are combined with runtime introspection to create
a unit test framework in the spirit of MiniTest. These
examples demonstrate the level of Ruby sophistication the reader has
attained by completing the book.
"The Well-Grounded Rubyist" is relatively up-to-date, covering Ruby 1.9.1 (current version is 1.9.2). The production quality is high, with no obvious errors (unlike "Rails AntiPatterns" which I read recently). My only criticism would be that the book is a touch long at 470 pages (not counting the index).. In particular, the summary sections at the end of each chapter add little value and should have been cut. This is a minor quibble and overall I would recommend Black's book to developers wanting to learn Ruby.