2.1. Talking to objects

In any Ruby program, the bulk of the design, logic, and action revolves around objects. When you write Ruby programs, your main activities are creating objects, endowing them with abilities, and asking them to perform actions. Objects are your handle on the universe of your program. When you want something done—a calculation, an output operation, a data comparison—you ask an object to do it. Rather than ask in the abstract whether a equals b, you ask a whether it considers itself equal to b. If you want to know whether a given student is taking a class from a given teacher, you ask the student, “Are you a student of this teacher?” Exactly how this kind of querying plays out, in terms of data structures and syntax, depends ...

Get The Well-Grounded Rubyist, Second Edition 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.