Skip Links

Network World

  • Social Web 
  • Email 
  • Close

(Comma separation for multiple addresses)
Your Message:

Book Review: Ruby by Example

Kevin C. Baird's book helps experienced programmers pick up Ruby skills, including Rails, with a series of well-explained example scripts.
By Brian Tanaka, LinuxWorld.com
September 12, 2007 11:18 AM ET
  • Share/Email
  • Tweet This
  • Comment
  • Print

Because of the continuing buzz about Ruby on Rails, an increasing number of people are stumbling upon and enjoying the language this popular MVC framework is based on: Ruby. Kevin Baird's book, Ruby by Example, helps experienced programmers sharpen their Ruby skills by exploring a series of well-explained example scripts.

Ruby has been around since 1995, but only relatively recently has it received widespread attention thanks to the continuing rise in popularity of Rails. In my personal experience, it's been interesting to watch attitudes held by hardcore Perl, Python, and PHP folks toward Ruby slowly change over the years: initial outright dismissal turned to suspicious mistrust, then distant critical scrutiny, and finally tentative experimentation. Even some of my dyed-in-the-wool Perl friends and colleagues are giving Ruby a try, albeit with a healthy dose of skepticism.

Another area I have noticed Ruby making inroads is as a teaching language for beginner programmers -- for example, Chris Pine's Learn to Program (Pragmatic Programmers, 2006). From what I've seen of Ruby, it's well-suited to the task.

Ruby by Example is intended to be accessible to both beginners and more experienced programmers, but ultimately — though I think it would be tempting on a bookstore shelf to a neophyte scanning the front and back covers — this book is best suited to those with some experience under their belts. Take, for example, the ternary operator in the first script in the book. A book aimed squarely at first time programmers probably wouldn't include a ternary in the first example. I don't mention this as a criticism, as the author clearly states in the introduction that the book is meant to be "accessible" to neophytes as opposed to being designed expressly for them.

The book is well-organized and begins with an introduction that explains what Ruby is and how to install it. Then, in the chapter one, Baird jumps right into the fun and begins explaining the basics via examples in Interactive Ruby (IRB).

IRB, for those unfamiliar with it, is an extremely useful feature of Ruby, an interactive shell in which you can try out snippets of code and see the results immediately. You can also load modules stored in external files by using the -r flag and use those modules interactively. For example:

 

  $ irb -r some_module.rb

The balance of the book is a veritable smorgasbord of example scripts, each with a detailed explanation. For each example, Baird follows a consistent formula: he describes the purpose of the script, lists the script itself, explains how it works, shows an example of running it, analyzes the results, and then further refines the script in some way. Each chapter concludes with a recap of any new concepts introduced within the chapter.

Though some of the scripts are a bit contrived, they are all great working examples of the concepts and techniques Baird teaches. Examples include a random signature generator, a palindrome tester, a command line argument parsing utility, a histogram generator, an XML validator, and 35 more. In addition to those 40 scripts, Baird explores four Ruby CGI scripts, and even runs through a basic Ruby on Rails project.

  • Share/Email
  • Tweet This
  • Comment
  • Print

Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a NetworkWorld account? Log in here. Register now for a free account.

Videos

rssRss Feed