DEV Community

Germán Alberto Gimenez Silva
Germán Alberto Gimenez Silva

Posted on • Originally published at rubystacknews.com on

Inside Ruby’s Object Model

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
Enter fullscreen mode Exit fullscreen mode

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.


👉 Read the full article.

Inside Ruby’s Object Model – Linking Ruby knowledge from the most remote places in the world.

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&#0…

favicon rubystacknews.com

Article content

Top comments (0)