Chapter 21. Ruby

Ruby is a relatively new scripting language designed by Yukuhiro Matsumoto as an alternative to Perl and Python ("more powerful than Perl, more object-oriented than Python" according the inventor). It was first released in 1995 and quickly gained popularity in Japan. Outside of Japan, the interest in Ruby was mainly sparked by "pragmatic programmers" (see [HUNT00]>), Andrew Hunt and David Thomas, with their book about Ruby [THOMAS00]>. Ruby combines aspects of such different origins as Perl and Smalltalk. It is considered by many the cleanest scripting language.

21.1. Software and Installation

Since there is only one Ruby implementation (the original one by the inventor) available for now, we don't have to choose between different dialects. We use the standard Windows distribution (which comes with an installer) as well as the Linux version. Part of the installation is an interactive shell called irb (for interactive Ruby) which is similar to the interactive environments we have used for Python, Lisp, and so forth. On Debian Linux, the interactive shell is contained in a second package (called irb) that you have to install together with the Ruby package itself.

Using the option --simple-prompt changes the prompt of the interactive shell to >> which is more suitable for our presentation than the longwinded standard prompt indicating module and line number. Like in Perl, we can manipulate the way the print statement separates fields and records using the special variables $, and $\. We will set the record separator to a space to simplify the examples.

References

The best book on Ruby is [THOMAS00]>. It is a passionate introduction to the language and introduced the language to a wider public (beyond people speaking Japanese). Their previous book [HUNT00]> pathed the way by telling developers to learn at least one new programming language every year.

Andrew Hunt and David Thomas, 020161622X, Addison Wesley Longman, 2000, The Pragmatic Programmer: From Journeyman to Master.

David Thomas and Andrew Hunt, 0201710897, Addison Wesley Longman, 2000, Programming Ruby.