Ruby for Rails Book

Ruby for Rails is a must have for Ruby on Rails developers.

While you could develop Rails applications without understanding Ruby, to do would completely miss out on the reasons Rails was created in Ruby. Ruby is a powerful and enjoyable language.

For those of you that do not know of David Black, here is a part of the bio from his book: “A Ruby community leader, David Black is the director of Ruby Central, the parent organization of the annual International Ruby Conference (RubyConf) and the International Rails Conference. David is a Ruby core contributor and the creator and maintainer of RCRchive.”

The reasons that I think you must know Ruby to become an effective and efficient Rails programming machine:

1. To understand the Rails source code

2. To make your Rails apps do something beyond pushing data in and out of a database.

3. To take advantage of “Ruby everywhere”

4. To use Ruby for non-Rails tasks (automation).

5. To enjoy developing Rails apps!

There are books on Ruby and there are Books on Rails. David Black is one of the only authors out there that can lead you over the bridge that connects Ruby and Rails. David obviously has a deep and broad understanding of Ruby that he puts to great use in this book. He uses this knowledge to lead you through not only how Ruby works, but also how Rails uses the power of the Ruby language to deliver an efficient and enjoyable framework. Here are some topics he covers:

Part 1: The Ruby Rails Landscape
The first two chapters are introductory overviews to getting your “Hello World” Ruby and Rails programs running. For anyone that has written a Rails program, there is not much new in the first part of the book.

Part 2: Ruby Building Blocks
The next section has a very interesting discussion about Rails as a domain specific language and how Rails feels more like configuration vs. programming. For example, David shows how the Rails declaration has_many :editions is a method call that could be written in several different ways. The Rails idiom of has_many :editions is syntax that makes Rails feel more like configuration and less like programming. This same method call could also be written in your controllers as send("has_many", "editions".intern) or has_many(:editions).

Similarly, David’s discussion of Ruby “syntatic sugar” is enlightening. Syntatic sugar of Ruby allows the programmer great power in the setter methods. It does it more easily and cleanly than other languages (in my opinion). For example, in the setter method
def price=(amount)
@price = amount
end

the method name is “def price=”.

To call the method would look like this:
ticket.price=(65.00)

By allowing you to put a space before the equal sign in the method name and allowing for parens to be optional, Ruby allows for a much more pleasant:
ticket.price = 65.00

What makes Rails great is the combination of Ruby’s flexibility as a language and its ability to support “syntactic sugar” combined with the Rails community’s positive support for coding conventions that have created standards. When reading and writing Ruby for Rails code, it is important to understand the differences between what is a Rails community standard and what is a Ruby language expectation. This understanding will give you the powers itemized above.

This combination of technical and philosophical conversation continues throughout the section brining to light important information on managing classes, constants, modules and mixins, control flow statements, and error handling. The books description of how Ruby yielding works is a valuable read and is a good example of how this book helps you understand what is going on in a Ruby program and how to become a good Ruby and Rails developer.

Part 3: Built-In Classes and Modules
This section is pure Ruby and describes things such as scalar objects, containers, collections and regular expressions. In my current project, this book’s 24 page discussion on Ruby regular expressions was worth the price of the book itself, allowing me to replace custom methods I had written with a few lines of regex. (email me at scott [at] synapsoftware [dot] com if you want the technical details on this statement)

Part 4: Rails Through Ruby, Ruby Through Rails
The book concludes with a step by step walkthrough of the sample application. It discusses not only the how but also the why of Ruby on Rails design decisions. That is what I liked best about this book.

The final chapter invites you to learn more by exploring the Rails source code. It steps through three techniques for discovering how Rails leverages Ruby.

This is a Ruby book first – details on many Rails features are not found here, and rightfully so. For example, except for mentioning that it is not mentioned, the book is missing any mention of testing (got that?). David stresses that testing is crucial, but feels it has been covered at length elsewhere.

Read this book to understand Ruby and to become the next Rails star on your team.

Advertisements
%d bloggers like this: