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 directly on the command line using a-e parameter.Program:
% 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 is more practical than thisCodeYou 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