2. Classes, Objects, and Modules
Object-oriented programming (OOP) is Ruby’s bread and butter. It’s often referred to as a purely object-oriented language because everything in Ruby is an object or can be turned into one, and I mean everything. From classes all the way down to numeric literals, Ruby exposes a consistent design that is found in few other languages.
Ruby’s object model was heavily influenced by Smalltalk and is probably a bit different than what you’re used to if you’re coming from languages like C++ or Java. The fact that classes are also objects is enough to send your mind into infinite recursion if you let it. Then there are some gotchas like subclasses not automatically initializing their superclasses and the ambiguity between ...
Get Effective Ruby: 48 Specific Ways to Write Better Ruby 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.