Chapter 4. Working with Objects

Working in Ruby is a joy because there is an internal consistency to the design. This consistency leads to expected (“least surprising”) behavior throughout the core Ruby classes, and this section is about that design. First, some ground rules:

An important detail to remember when working with Ruby is that all objects are subclassed from Object in some way; indeed, every object class that you create yourself will be a subclass of the class Class; in turn, Class is a subclass of Object. As I mention later, every new class also mixes in methods and properties of the Module class.

Object also mixes in methods from the Kernel module. This ensures that methods such as #gets, #puts, and #p work no matter which scope you ...

Get Ruby Phrasebook 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.