13.3. BasicObject as ancestor and class

BasicObject sits at the top of Ruby’s class tree. For any Ruby object obj, the following is true:

obj.class.ancestors.last == BasicObject

In other words, the highest-up ancestor of every class is BasicObject. (Unless you mix a module into BasicObject—but that’s a far-fetched scenario.)

As you’ll recall from chapter 3, instances of BasicObject have few methods—just a survival kit, so to speak, so they can participate in object-related activities. You’ll find it difficult to get a BasicObject instance to tell you what it can do:

>> BasicObject.new.methods.sort
NoMethodError: undefined method `methods' for #<BasicObject:0x007fafa308b0d8>

But BasicObject is a class and behaves like one. You can get information ...

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.