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 ...
Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.