Introduced
This is a short introduction to Ruby and it takes only 20 minutes to complete the reading. This assumes that the reader has already installed Ruby, and if you are not installing it, please visit the official Ruby website for download and installation before reading.
Interactive Ruby
Open irb (interactive ruby Shell):
If you are using Mac OS X, open the Terminal window to enter IRB;
If you use Linux, open the shell and enter IRB;
If you are using Windows, please find Ruby->fxri in the Start menu and execute it.
OK, after you open IRB, enter "Hello World" in it.
Ruby, listen to your schedule!
What happened? Have we just written the world's most short "Hello Worlds" program? That's not exactly true. The second line of output is IRB tells us: The evaluation result of the previous expression. If we want to print "Hello world", we need a little more effort:
Puts is a simple print output command in Ruby. What is the "=> nil" behind it? --that's the result of an expression. Puts always returns nil, a way in which Ruby represents "absolutely no value" (absolutely-positively-nothing value), and looks somewhat like a null in Java.