BasicObject
For most purposes in Ruby, you can consider the Object class to be the root of Ruby’s class hierarchy, and the Kernel module to be mixed into all objects. But in some specialized classes, you might want a Ruby object that doesn’t have the basic functionality contained in Object and Kernel. For example, you might want a very minimal data object, or you might want to experiment with your own metaprogramming tools or object semantics.
For those cases, you want the class BasicObject which is the real root of Ruby’s class hierarchy. BasicObject deliberately has just a few methods, allowing it to be conveniently used as the basis for a number of metaprogramming techniques.
If you write code in a direct descendent of BasicObject, you won’t ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access