% ruby ??-v
(-v tells The interpreter prints out the Ruby version), and then press Enter. If Ruby is installed, you will see information similar to the following:
% ruby ??-v
ruby 1.6.6 [i586-linux]
If Ruby is not installed, you can ask the administrator to install it, or you can do it yourself, Ruby is a free software with no installation or usage restrictions.
Now, let's play with Ruby. You can do it through a- The e parameter places a Ruby program directly on the command line:
% ruby ??-e 'print "hello world\n"'
hello world
Generally, Ruby programs are saved in a file ri.
% cat > test.rb
print "hello world\n"
^D
% cat test.rb
print "hello world\n"
% ruby ??test.rb
hello world
^D refers to control-D. The above is the situation under UNIX. If you use DOS, then this is:
C:\ ruby> copy con: test.rb
print "hello world\n"
^Z
C:\ruby> type test.rb
print "hello world\n" < br />C:\ruby> ruby ??test.rb
hello world
When writing more practical code than this, you'll want to use a real text editor!
Some Surprisingly complex and useful things can be done with a one-line mini-program. For example, this thing replaces foo with bar in all C source programs and header files in the current directory, and appends a " to the original file. bak" backup:
% ruby ??-i.bak -pe 'sub "foo", "bar"' *.[ch]
This program is similar to the cat command under UNIX (but slower than cat ):
% ruby ??-pe 0 file