A deep dive into how MRI/CRuby implements Ruby's object model at the C level. Covers how include inserts T_ICLASS proxy nodes (sharing method tables rather than copying), how prepend rewires the ancestor chain via an origin node, how extend is simply include on a singleton class, and how class methods are singleton methods on class objects. Also explains the parallel singleton class hierarchy that enables class method inheritance, the full method resolution order (MRO), and how refinements work as scoped monkey patches. The post traces these mechanisms through MRI source files like object.c, class.c, and vm_method.c.
Table of contents
Build Maps Without Google APIs1. The Root of Ruby’s Object System2. Why Object Already Has Methods3. Module Is the Real Core of Ruby4. How include Really Works5. The Secret of T_ICLASS6. Why Duplicate Includes Don’t Happen7. extend Is Just include on a Singleton Class8. Singleton Classes (Eigenclasses)9. Why Class Methods Work10. The Hidden Parallel Hierarchy11. prepend Changes Everything12. The Real Magic Behind prepend13. Method Lookup in MRI14. Complete MRO Example15. Refinements: Scoped Monkey Patching16. Ruby’s Object Model Is a Linked Graph17. Final ThoughtsSort: