First, you must check whether Ruby has been installed. At the shell prompt ("%" here, so do not enter % ),
% Ruby-v
(-V tells the interpreter to print out the Ruby version) and 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 without installation or restrictions.
Now, let's play with Ruby. You can place a Ruby program directly on the command line using a-e parameter:
% Ruby-e 'print "hello world \ n "'
Hello world
Generally, Ruby programs are stored in a file.
% 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 in UNIX. If you use DOS, it will be like this:
C: \ ruby> copy con: test. rb
Print "hello world \ n"
^ Z
C: \ ruby> type test. rb
Print "hello world \ n"
C: \ ruby> ruby test. rb
Hello world
When writing code that is more practical than this, you will want to use a real text editor!
Some Amazing complex and useful things can be made using a line of command mini program. for example, replace foo in all C source programs and header files in the current directory with bar and append the original files ". bak "backup:
% Ruby-I. bak-pe 'sub "foo", "bar" '*. [ch]
This program is similar to the cat command in UNIX (but slower than cat ):
% Ruby-pe 0 file