O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

First Steps

In deference to a tradition started with the classic book that taught so many people how to program in C, The C Programming Language by Brian Kernighan and Dennis Ritchie, let's crank out the obligatory “Hello, world!” program. Try typing this directly into a terminal window:

% ruby
						-e 'puts "Hello World!"'
Hello World!

Life in the Command Line

Was that really a program? Well, yes. A program that does something simple, such as print a message, needs no elaborate structure. In fact, the program proper lives within the single quotes, and is this:

							puts "Hello World!"
						

As you might guess, puts means to put a string of characters someplace, in this case the screen.

The code that surrounds the program is our way of starting the Ruby ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required