About the Reviewer
Bart Vrancken has a Masters degree in Informatics. He is a Sun Certified Java Programmer and works as a Java-architect for Datasoft Services. He fills most of his "free" time being chairman of a solidarity choir, called Caminhando.
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.

Ruby Cookbook



Author(s) Lucas Carlson, Leonard Richardson
Publisher O'Reilly
PubDate July 2006
Reviewer Bart Vrancken
Purchase and help Javalobby



Table of Contents




One Minute Review

Positives
  • Good reference material
  • Good problem-solving format
  • Great discussions about their solution to a given problem
  • Recipes are covering basic and advanced problems
Negatives
  • None

Sections

Intent & Audience

back to top Back to top

A lot of the problems you have while programming in Ruby are the same as those of everyone else in the Ruby world. With this book, the authors want to save the time of the readers by explaining their solutions to these problems, with the intention that the reader will have more time to solve the more interesting problems of her/his particular project. The book is for intermediate and advanced Ruby developers.

back to top Back to top

Relevance of material

With the different kind of topics, the authors have covered the most important problems that you encounter while programming something. I recommend that you skim through the book. This will enable you to know about all the recipes the authors are providing. But, I think that the book, at its best, can be used as a reference material. Whenever you have an actual problem during programming (AND you do not wish to reinvent the wheel), you will find a good solution for it in this book.

Let me mention upfront that the book is big in size, and it does offer solutions to a whole range of challenges when programming in Ruby. The authors have done a fantastic job of providing a lot of pointers to resources where you can find even more information about the subject.
 

back to top Back to top

Chapter highlights

Every chapter begins with a short introduction of tackled subjects. Then a lot of recipes are following. A recipe is always giving a solution to a given problem. After the solution, a discussion is going further then the problem, going more deeply into the language.

The first 6 chapters are dealing with algorithmic problems of Ruby's built-in data structures.

Chapter 1 deals with strings. Textmanipulation is important in most of the languages, so 20 recipes are given, beginning from building a string from parts till validating an Email Address and even classifying text with a Bayesian Analyser for seperating the spam from the real Email.

Numbers are discussed in chapter 2 of this cookbook. First the representation of real numbers, complex numbers, arbitrary-precision decimals are given. Then common mathematical and statistical algorithms that are implemented in Ruby, like random numbers and logarithms and conversions between the base types are provided to come to given recipes of simple implementations for finding the mean, median to the more complex mathematical algorithmes of multiplying matrices and linear equations. The most advanced recipe will be that of simulating a subclass of a numeric type. You can make subclasses of the basic types, but they will be useless, because they don't have constructors. A workaround with delegation is provided as solution. The chapter concludes with the classical examples of Fibonacci, prime numbers and Credit Card Checksums.

Ruby has 2 different interfaces for dealing with time. Chapter 3: Date and Time is covering them both, giving the different advantages and disadvantages of each interface. The native interface to the C libraries is faster than the Ruby library but lacks a couple of features like times before 1901 or after 2037. I believe the chapter is very complete about the matter of date and time, including a table with the different formatting directives, if you want to print a date.

Chapter 4: Arrays is an introduction of this simple but important compound data type. After a fast introduction about the definition of an array, recipes are given for iterating, rearranging, reversing, sorting an array. After these basic operations, the chapter continues with more advanced algorithms like sorting by frequency, shuffling and doing set operations on an array. Chapter 5 does the same with Hashes, first basic operation, till doing a search on a hash with regular expressions.

Chapter 6 is giving some diner-ready recipes for all the basic operations you must do with files and directories.

The next 4 chapters are more about the language of Ruby.
Chapter 7. Code Blocks and Iterations is explaining the use of lambda by creating code blocks, how to use in a method and how to iterate or change the iterations over those blocks.
In chapter 8 the core-business of an object-oriented language is tackled: Objects and Classes. With topics like holding data in a class, delegation, inheritance and access control, a lot of things are explained how you can manipulate classes. In chapter 9 Modules and Namespaces the book continues with simulating multiple inheritance by working with modules. The last chapter of this serie: chapter 10 Reflections and Metaprogramming goes to the most advanced topics of a computer language. From fixing bugs in other classes till aspect-oriented programming is discussed.

The next part of the book covers popular ways to store your data. Chapter 6 already discussed the basic file operations, but Chapter 11 goes for an explanation about XML and HTML with all the typical problems that you encounter when you want to read webpages or RSS feeds. Chapter 12 Graphics and Other File Formats covers images, Excel, Gzip, Tar, ZIP, PDF and MIDI. Chapter 13 Databases and Persistence is giving various ways to save your data in files and databases.

The next triplet of chapters is about network applications. Chapter 14: Internet Services goes about all the different network-protocols like DNS, FTP, SSH, IMAP, POP3 and ends with making your own internet server. So everything you need to know about the network, except for the killer framework of Ruby on Rails. The subject that is covered in the largest chapter of the book: chapter 15. 61 pages are not enough for this framework, only the basics are covered and a pointer to the Rails Cookbook is given for more recipes. Chapter 16: Web Services and Distributed Programming concludes this part of the book with using and making webservices, like searching for Amazon books and writing a SOAP client and server. The second half of the chapter give some examples how you can do distributed programming in Ruby.

Chapter 17 has a very honest title: Testing, Debugging, Optimizing, and Documenting and indeed there are recipes for those 4 subjects in it. Ruby's Gem packaging system is covered in chapter 18: Packaging and Distributing Software and chapter 19 Automating Tasks with Rake is devoted to Rake, the build tool for Ruby.

The book ends with 4 miscellaneous topics that are definitely worth reading.
Chapter 20: Multitasking and Multithreading goes over services and working with threads.
Chapter 21: User Interface can make your programs interact with the user, in command-line way or more graphical.
A very short chapter 22 Extending Ruby with Other Languages that touches quickly the use of C in Ruby and JRuby.
The last chapter (23) are out of the box recipes for system administration.

back to top Back to top

Rating

It is not an introductory book for Ruby and honestly I used the references given in the book to start with Ruby, because I didn't know anything of the language. Later on, when I got some feeling about the language, I started to enjoy the book, because it is giving a lot of information in the discussions that goes widely over the initial given problem for understanding more of its philosophy. It 's a big book, but it is also giving a lot of recipes to real-world problems. If I 'm going to program something in Ruby, I will search a good starting point recipe, that will give me a hint to a good solution of the problems I 'll encounter. I would recommend the book to everyone who programs in Ruby.

Relevance
Readability
Overall

back to top Back to top

Resources

Programming Ruby: The Pragmatic Programmer's Guide
Why's (Poignant) Guide to Ruby," by "why the lucky stiff

Purchase this book on Amazon and help Javalobby.