The easiest way to run Ruby interactively is simply to type ``ruby''
at the shell prompt.
puts "Hello, world!"
Here we typed in the single
an end of file character (which is control-D on our system).
This process works, but it's sort of painful if you make
a typo, and you can't really see what's going on as you type.
directory in the Ruby distribution you'll find
a script named ``
''. It goes one step better by showing us
the value of each expression as it is entered:
% cd sample
% ruby eval.rb
ruby> a = "Hello, world!"
ruby> puts a
Here we can see the output from
, and then the return value
That's all fine and well, except that multiline expressions do not
work, and you can't edit the line you're on, or go back and use
previous lines (as you might with command history in a shell).
For the next step up from
, we have
is a Ruby Shell, complete with command-line history,
line editing capabilities, and job control. It is quite configurable
and has many options, so much so that it has its own appendix beginning
on page 517. We recommend that you get familiar with
so you can try some of our examples interactively.