Programming Ruby: A Book Review

December 1st, 2001 by Ralph Krause in

Part tutorial, part reference manual, this book takes on the Ruby programming language.
Your rating: None Average: 3 (1 vote)

"Use Ruby and you'll write better code, be more productive, and enjoy programming more", touts the introduction to this book. Such claims are commonplace for virtually every programming language out there, but are these claims true for Ruby?

Programming Ruby, written by David Thomas and Andrew Hunt, is part tutorial and part reference manual. Ruby is an object-oriented, interpreted language, written by Yukihiro Matsumoto, that has a large following in Japan (its usage is currently rumored to surpass that of Python) and is gaining popularity elsewhere. In addition to ample built-in functionality, Ruby also has a large selection of libraries and toolkits under development.

The book is divided into four parts, with a tutorial and language introduction contained in the first two parts, making up slightly less than half of the book. Part I is a tutorial that introduces concepts unique to Ruby along with basic syntax. Topics covered in this part include Ruby classes, standard variable types, loops, error handling, basic I/O and multithreading. Ruby's debugger and profiler are also introduced here.

Part II discusses how Ruby interacts with its world via command-line arguments and environment variables. It also illustrates how Ruby works in other environments, such as the X Window System using Ruby/Tk, the Web as CGI scripts executed by mod_ruby on the Apache web server and under Microsoft Windows. The section finishes by explaining how to extend the Ruby language by writing C programs and provides sample code for doing so.

The third part of the book starts with a concise recap of the material presented in earlier tutorials, then moves on to advanced topics. These advanced topics include how Ruby programs can guard against system modification by external data (important when using Ruby for CGI scripting), reflection (the ability of a running program to examine aspects of itself) and distributed programming.

Part IV provides a reference for Ruby's built-in classes and modules. This section also covers selected standard library modules such as Ruby's object-oriented design libraries, network and web libraries. An overview of each module is presented, followed by an alphabetical listing of its properties and methods, complete with a brief explanation and code snippet illustrating usage.

The final part of the book contains appendices on embedded documentation, the interactive Ruby shell, sources for Ruby support and a bibliography.

New Ruby programmers can read through Parts I and II to get an understanding of how Ruby works. Those familiar with other object-oriented languages, or trying to find specific Ruby functionality, can jump to the reference sections of the book.

The book's writing is generally clear and illustrations help clarify difficult concepts, but there is room for some improvement. For example, code in later chapters depends on code from earlier chapters, but this isn't always pointed out. Also, the code snippets aren't labeled, just mixed in with the text, which can make it difficult to find the needed code.

A powerful feature of Ruby is code blocks, used when writing iterators or defining code to be run under transactional control. The book presents several examples of blocks and iterators, but they don't seem very illuminating. Some figures or a bit more explanation in the text would be welcome.

All of the example code that I tried worked, except for the HTTP example on page 111. A look at the book's web site didn't provide an answer to the problem, but I did find a workaround by doing a search of comp.lang.ruby in the Google/Deja News archives.

I would also have liked to see more examples of complete Ruby programs like the last Ruby/Tk example on page 161. This would help illustrate how to put all the pieces of a Ruby program together and how modules and classes interact.

I think Programming Ruby is a good book, and I did gain an understanding of what Ruby is and how it works. I found some code examples, such as the Ruby/Tk programs, useful and informative. The book does lack depth when explaining concepts such as code blocks, however, and this could keep it from being the only Ruby book that you would need.

Product Information and Resources

Ralph Krause lives in Michigan and has been using Linux for over three years. He is working at becoming a prolific writer, highly sought after web designer and a happy programmer.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

July 2009, #183

News Flash: Linux Kernel 3.0 to include an on-the-go Expresso machine interface! Ok, maybe not, but Linux is definitely going mobile, from phones to e-readers. Find out more inside about Android, the Kindle 2, the Western Digital MyBook II, The Bug, and Indamixx (a portable recording studio). And if you've gone mobile and you been wanting more Emacs in your life then check out Conkeror.


To compliment the mobile we've got the stationary: parsing command line options with getopt, checking your Ruby code with metric_fu, and building a secure Squid proxy. How is this stationary you ask? What can we say? It's not. We just wanted to see if anybody actually read this part of the page :) .


All this and more, and all you have to do is get your hot sweaty hands on the latest copy of Linux Journal.





Read this issue