Chapter 1. Strings, Numbers, Classes, and Objects

image with no caption

The first thing to know about Ruby is that it’s easy to use. To prove this, let’s look at the code of the traditional “Hello world” program:

1helloworld.rb

puts 'hello world'

That’s it in its entirety. The program contains one method, puts, and one string, “hello world.” It doesn’t have any headers or class definitions, and it doesn’t have any import sections or “main” functions. This really is as simple as it gets. Load the code, 1helloworld.rb, and try it.

Getting and Putting Input

Having “put” a string to the output (here, a command window), the obvious next step is to “get” a string. As you might ...

Get The Book of Ruby 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.