5.1. Understanding self, the current/default object

One of the cornerstones of Ruby programming—the backbone, in some respects—is the default object or current object, accessible to you in your program through the keyword self. At every point when your program is running, there’s one and only one self. Being self has certain privileges, as you’ll see. In this section, we’ll look at how Ruby determines which object is self at a given point and what privileges are granted to the object that is self.

5.1.1. Who gets to be self, and where

There’s always one (and only one) current object or self. You can tell which object it is by following the small set of rules summarized in table 5.1. The table’s contents will be explained and illustrated as we ...

Get The Well-Grounded Rubyist, 2nd Edition now with the O’Reilly learning platform.

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