For this online version of this book, the Ruby execution environment is always available. If you just want to use the Zamples live online faciltiy to work through the material in this book, you can skip down a bit.
First, you'll want to check whether ruby is installed. From
the shell prompt (denoted here by "%", so don't type the
%), type
(-v tells the interpreter to print the version of ruby),
then press the Enter key. If ruby is installed, you will
see a message something like the following:
If ruby is not installed, you can ask your administrator to install it, or you can do it yourself, since ruby is free software with no restrictions on its installation or use.
Now, let's play with ruby. You can place a ruby program
directly on the command line using the -e option:
More conventionally, a ruby program can be stored in a file.
When writing more substantial code than this, you will want to use a real text editor!
Using Zamples
You can run the same program online using Zamples by clicking the Try It button below.
puts 'hello world' |
Some surprisingly complex and useful things can be done with
miniature programs that fit in a command line. For example, this
one replaces foo with bar in all C source
and header files in the current working directory, backing up the
original files with ".bak" appended:
This program works like the UNIX cat command (but works
slower than cat):


