Chapter 5. The default object (self), scope, and visibility
- The role of the current or default self object
- Scoping rules for local, global, and class variables
- Constant lookup and visibility
- Method-access rules
In describing and discussing computer programs, we often use spatial and, sometimes, human metaphors. We talk about being “in” a class definition or returning “from” a method call. We address objects in the second person, as in obj.respond_to?("x") (that is, “Hey obj, do you respond to 'x'?”). We use these metaphors to describe the context of the program at any given point. Context is important when discerning the value of an identifier or the state of an object. As a program runs, its context ...
Get The Well-Grounded Rubyist, Third 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.