Chapter 2. A Quick Tour of Ruby

Without going into all the details, this chapter introduces you to the fundamentals of Ruby: classes and modules, including the Object class and the Kernel module, reserved words (keywords), comments, variables, methods, and so forth. Most topics will be dealt with elsewhere in the book in more detail. Some topics merit entire chapters, others only sections (found in Chapter 10). I’ll always tell you where else to look for more information on a topic. This book’s most detailed discussions on methods and blocks are found in this chapter.

Ruby Is Object-Oriented

Matz, the creator of Ruby, had wanted to create his own programming language since he was in high school. He wanted to create a scripting language, but he also wanted it to be object-oriented.

Ruby goes beyond mere scripting, though its programs may look like shell scripts. It is not just a procedural language, but it can be used like one.

Ruby has classes. Classes hold data—in the form of variables and constants—and methods, which are compact collections of code that help you perform operations on data. Classes can inherit information from each other, but only one at a time. This allows you to reuse code—which means you’ll spend less time fixing or debugging code—and intermix the code through inheritance.

A class is like a blueprint; with a new method, this blueprint can be assigned to a variable or become instantiated, and thereby become an object. In Ruby, almost everything is an object; in fact, ...

Get Learning 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.