Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
930
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How is magic formed
Short excursion into Ruby Internals, Ruby Usergroup Berlin, June 3rd 2014
Rin Raeuber
July 03, 2014
More Decks by Rin Raeuber
See All by Rin Raeuber
Das Internet of Things mit dem ESP2866
rin
0
190
Let's create a game with Ruby
rin
1
130
Hallo, wir sind die Cyborgs: Implantate, Body-Hacks und Rock ‘n Roll
rin
1
110
Let's go to Mars #rp14
rin
0
300
Angular Directives For The Rest Of Us
rin
1
360
Other Decks in Programming
See All in Programming
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
600
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
180
Event is what happens
moro
2
3.1k
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
130
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.6k
No More NoSuchMethodError
exoego
1
120
Next.js: The final boss of Web Performance
guaca
0
380
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
2.7k
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
160
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
350
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
140
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
230
Featured
See All Featured
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
59k
Technical Leadership for Architectural Decision Making
baasie
3
630
Mind Mapping
helmedeiros
1
420
Design in an AI World
tapps
1
380
The Curious Case for Waylosing
cassininazir
1
600
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
380
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
My Coaching Mixtape
mlcsv
0
380
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Automating Front-end Workflow
addyosmani
1370
210k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.4k
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