Simple Classes

Procedural programming approaches an application by defining the steps that need to be taken. Conversely, object-oriented programming focuses on the data being used by an application. With this approach, a class needs to represent the application’s data in terms of both the information that needs to be stored and the sorts of tasks that will be done with the data. Information can be represented in variables (called attributes or properties when in classes) and functions (called methods). As a theoretical but approachable example, think of a person: a person has attributes—name, age, etc.—and methods—eating, sleeping, and so forth.

A basic class definition begins with the keyword class, followed by the name of the class. The code ...

Get Ruby: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.