May 21, 2026
How MRI Really Implements include, prepend, extend, Singleton Classes and Method Lookup
Ruby’s object model looks elegant from the outside:
module Logging
def call
puts "before"
super
end
end
class Service
prepend Logging
def call
puts "service"
end
end
But internally, MRI/CRuby performs a surprising amount of machinery to make this work.
Under the hood:
- include does not copy methods
- prepend rewires the method lookup chain
- extend injects modules into singleton classes
- class methods are singleton methods
- inheritance is literally a linked list of internal structures
- method lookup walks internal C-level tables
This article explores how Ruby’s object model actually works by following the MRI source code itself:
- object.c
- class.c
- eval.c
- vm_method.c
- proc.c
The goal is not just to learn Ruby syntax.
The goal is to understand how Ruby thinks.


Top comments (0)