Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How is magic formed
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Rin Raeuber
July 03, 2014
Programming
0
880
How is magic formed
Short excursion into Ruby Internals, Ruby Usergroup Berlin, June 3rd 2014
Rin Raeuber
July 03, 2014
Tweet
Share
More Decks by Rin Raeuber
See All by Rin Raeuber
Das Internet of Things mit dem ESP2866
rin
0
180
Let's create a game with Ruby
rin
1
110
Hallo, wir sind die Cyborgs: Implantate, Body-Hacks und Rock ‘n Roll
rin
1
94
Let's go to Mars #rp14
rin
0
260
Angular Directives For The Rest Of Us
rin
1
340
Other Decks in Programming
See All in Programming
今から始めるClaude Code超入門
448jp
8
9.3k
CSC307 Lecture 10
javiergs
PRO
1
680
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
440
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
170
SourceGeneratorのススメ
htkym
0
480
ふん…おもしれぇ Parser。RubyKaigi 行ってやるぜ
aki_pin0
0
110
Data-Centric Kaggle
isax1015
2
810
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1.1k
CSC307 Lecture 06
javiergs
PRO
0
700
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
160
AgentCoreとHuman in the Loop
har1101
5
270
AI & Enginnering
codelynx
0
140
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.4k
We Are The Robots
honzajavorek
0
170
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
120
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
290
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
110
Transcript
How is ! magic ! formed
Rin! @rinpaku @bitcrowd
None
WHY?
TIL: There’s bacon in! the Ruby source code
What happens when Ruby runs my code?! ! What is
an Object?
What happens ! when Ruby ! runs my code?
Ruby code 9.times do puts "Ente" end
Tokens 9 . t i m e s …
9 . times do puts "" Tokens 9 . t
i m e s … integer identifier identifier period keyword strin
Syntax Tree do_block period method_add_block integer! 9 identifier! times call
command identifier! puts …
YARV instructions “Yet Another Ruby Virtual Machine” == catch table
| catch type: break st: 0002 ed: 0006 sp: 0000 cont: 0006 |-------------------------------------------------------------- 0000 trace 1 0002 putobject 9 0004 send <callinfo!mid:times, argc:0, block:block 0006 leave == disasm: <RubyVM::InstructionSequence:block in <compiled>@<co == catch table | catch type: redo st: 0000 ed: 0009 sp: 0000 cont: 0000 | catch type: next st: 0000 ed: 0009 sp: 0000 cont: 0009 |-------------------------------------------------------------- 0000 trace 256 0002 trace 1 0004 putself 0005 putstring "Ente"
I MIGHT! HAVE MADE THIS ALL UP
Tokenizing Ripper.lex(your_code)
parse.c
with Ripper: Ripper.sexp(your_code) ! Parsing
with Ripper: Ripper.sexp(your_code) parser debug information: ruby -y example.rb Parsing
RubyVM::InstructionSequence. compile(code).disasm Compiling
What ! is an! Object?
struct meetup { char title[120]; time_t starts_at; bool has_talks; };
Structs
union location { char address[120]; struct position { int latitude;
int longitude; } }; Union
struct meetup { char title[120]; time_t starts_at; bool has_talks; union
{ char address[120]; struct position { int latitude; int longitude; } } };
Let’s look at some source code
RObject struct RObject { struct RBasic basic; … };
RBasic struct RBasic { VALUE flags; const VALUE klass; };
RObject struct RObject { struct RBasic basic; struct { long
numiv; VALUE *ivptr; struct st_table *iv_index_tbl; } heap; }; simplified
RObject struct RObject { struct RBasic basic; union { struct
{ long numiv; VALUE *ivptr; struct st_table *iv_index_tbl; } heap; VALUE ary[ROBJECT_EMBED_LEN_MAX]; } as; };
RFloat struct RFloat { struct RBasic basic; double float_value; };
- Reading C is not that bad.* *(If you
hate it, you can still look at the Standard Library or Rubinius.)! ! - Check out the Ruby source code and give a talk about it. ;) Things to take home
WAIT! Where’s the bacon?
Never create Ruby Strings longer than 23 characters ! Ruby
under a microscope (the book) ! The Ruby Hacking Guide (Warning: Ruby 1.7.3!) ! A Tour of the Ruby MRI Source Code with Pat Shaughnessy Some Links