Ruby Document Center-Learning to start _ruby topics

Source: Internet
Author: User
First, you have to check if Ruby is installed. In the shell prompt entered prompt (here is expressed as "%", so don't typing%), typing

% Ruby-v


(-V tells the interpreter to print out Ruby version) and then knocks in the carriage. If Ruby is installed, you will see a message similar to the following:

% Ruby-v
Ruby 1.6.6 (2001-12-26) [I586-linux]


If Ruby is not installed, you can have the administrator install it, or you can do it yourself, Ruby is a free software that does not have the installation or use restrictions.

Now, let's play with Ruby. You can place a Ruby program directly on the command line with an-e argument:

% ruby-e ' print ' Hello world\n '
Hello World


In general, Ruby programs are saved 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. Above is the case under UNIX. If you use DOS, that's it:

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 more practical code than this, you will want to use a real text editor!

Something incredibly complex and useful can be done with a single line of commands. For example, this gadget replaces Foo in all C-source programs and header files in the current directory with bar and appends the original file with a ". 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.