SlideShare a Scribd company logo
CORE RUBY: HOW IT
WORKS
Back to Basics
A Success Story
Why Ruby?
A Journey To RUBY
My code’s journey through Ruby
Sample.r
b
Tokenize Parse Compile
YARV
instructio
ns
Tokens AST
Nodes
Your Code has a long road to take before
Ruby ever runs it.
- Pat Shaughnessy
Starter
Tokenization
1 0 . t i m e s d
o
| n |
. t i m e s d
o
| n |
tINTEG
ER
10
Tokenization (Cont.)
. t i m e s d
o
| n |
tINTEG
ER
10
t i m e s d
o
| n |
tINTEG
ER
10
.
tINTEG
ER
10
.
tIDENTIFIE
R
times
Keyword_do | |
tIDENTIFIE
R
n
Tokenization (Cont.)
Parsing
 Ruby uses a parse.c file, which is a parser
generator.
 It consists a parse.y file which contains
grammar rules
 Parser generator:
- input: tokens
- output: tokens that follow the grammar rules
 parse.c file uses LALR (Look-ahead Left
Reversed Rightmost Derivation) Algorithm
Parsing (Cont.)
Parsing (Cont.)
AST (Abstract Syntax Tree)
program
binary
Integer
5
plus
Integer
5
Compilation
 Before Ruby 1.9,
there was no
compiler.
 Using YARV, you
compile your code
into bytecode (like
JVM)
 JVM compiles the
bytecode with JIT
compiler, Ruby
interprets the
bytecode
Hey, Isn’t it too complex?
Compilation (Cont.)
 Why this extra compiler added from version
1.9?
 Answer: Speed. A compiled program with YARV is
much faster (~ 4.25 times) than traversing AST
nodes.
 Okay, Now what?
 Answer: Now let’s taste the magic of Ruby.
Thanks to “Matz”.
 Enough! Why do we need this actually?
 Isn’t it awesome to know how a language works
internally?
From, Dohatec
Thanks, I’m Imtiaz Hossain Emu

More Related Content

PPTX
Learn python – for beginners
PPT
Rockit: A Parser Generator for Ruby
PPTX
Php extensions
ODP
Piloting processes through std IO at the Ruby Drink-up of Sophia, January 2012
PDF
Parsing Expression Grammars and Treetop
PDF
What's new in Perl 5.12?
PDF
Project Linne 徵音梅林 -- Virtual Singer Sound-bank Processed with Python
PPTX
Cryptocurrency && Ruby
Learn python – for beginners
Rockit: A Parser Generator for Ruby
Php extensions
Piloting processes through std IO at the Ruby Drink-up of Sophia, January 2012
Parsing Expression Grammars and Treetop
What's new in Perl 5.12?
Project Linne 徵音梅林 -- Virtual Singer Sound-bank Processed with Python
Cryptocurrency && Ruby

What's hot (15)

PDF
오픈소스 라이브러리 개발기
PDF
Lets learn Python !
PPTX
PDF
Programming with Python - Basic
PDF
Introduction to python
PDF
PyCon 2013 : Scripting to PyPi to GitHub and More
PDF
Python in real world.
PDF
Python Workshop
DOCX
Unit 5 dwqb ans
PDF
Hacking the Python AST
PPTX
The .NET developer's introduction to IronPython
ODP
C 檔案輸入與輸出
PDF
Python basics_ part1
PDF
4Developers 2018: The turbulent road to byte-addressable storage support at t...
오픈소스 라이브러리 개발기
Lets learn Python !
Programming with Python - Basic
Introduction to python
PyCon 2013 : Scripting to PyPi to GitHub and More
Python in real world.
Python Workshop
Unit 5 dwqb ans
Hacking the Python AST
The .NET developer's introduction to IronPython
C 檔案輸入與輸出
Python basics_ part1
4Developers 2018: The turbulent road to byte-addressable storage support at t...
Ad

More from Ruby Bangladesh (7)

PPTX
RubyConf Bangladesh 2017 - Introduction to Ruby on Rails
PPTX
RubyConf Bangladesh 2017 - Speed up your API/backend
PPTX
RubyConf Bangladesh 2017 - Craft beautiful code with Ruby DSL
PPTX
RubyConf Bangladesh 2017 - Which language should I choose
PPTX
RubyConf Bangladesh 2017 - Elixir for Rubyists
PPTX
RubyConf Bangladesh 2017 - Rails buggy code
PPTX
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
RubyConf Bangladesh 2017 - Introduction to Ruby on Rails
RubyConf Bangladesh 2017 - Speed up your API/backend
RubyConf Bangladesh 2017 - Craft beautiful code with Ruby DSL
RubyConf Bangladesh 2017 - Which language should I choose
RubyConf Bangladesh 2017 - Elixir for Rubyists
RubyConf Bangladesh 2017 - Rails buggy code
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Ad

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
ai tools demonstartion for schools and inter college
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
System and Network Administraation Chapter 3
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
medical staffing services at VALiNTRY
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administration Chapter 2
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
assetexplorer- product-overview - presentation
PDF
Nekopoi APK 2025 free lastest update
PDF
PTS Company Brochure 2025 (1).pdf.......
Design an Analysis of Algorithms I-SECS-1021-03
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
CHAPTER 2 - PM Management and IT Context
VVF-Customer-Presentation2025-Ver1.9.pptx
ai tools demonstartion for schools and inter college
L1 - Introduction to python Backend.pptx
Transform Your Business with a Software ERP System
System and Network Administraation Chapter 3
Digital Systems & Binary Numbers (comprehensive )
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
medical staffing services at VALiNTRY
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administration Chapter 2
Which alternative to Crystal Reports is best for small or large businesses.pdf
assetexplorer- product-overview - presentation
Nekopoi APK 2025 free lastest update
PTS Company Brochure 2025 (1).pdf.......

RubyConf Bangladesh 2017 - Core Ruby: How it works

  • 1. CORE RUBY: HOW IT WORKS Back to Basics
  • 4. A Journey To RUBY My code’s journey through Ruby Sample.r b Tokenize Parse Compile YARV instructio ns Tokens AST Nodes
  • 5. Your Code has a long road to take before Ruby ever runs it. - Pat Shaughnessy Starter
  • 6. Tokenization 1 0 . t i m e s d o | n | . t i m e s d o | n | tINTEG ER 10
  • 7. Tokenization (Cont.) . t i m e s d o | n | tINTEG ER 10 t i m e s d o | n | tINTEG ER 10 . tINTEG ER 10 . tIDENTIFIE R times Keyword_do | | tIDENTIFIE R n
  • 9. Parsing  Ruby uses a parse.c file, which is a parser generator.  It consists a parse.y file which contains grammar rules  Parser generator: - input: tokens - output: tokens that follow the grammar rules  parse.c file uses LALR (Look-ahead Left Reversed Rightmost Derivation) Algorithm
  • 11. Parsing (Cont.) AST (Abstract Syntax Tree) program binary Integer 5 plus Integer 5
  • 12. Compilation  Before Ruby 1.9, there was no compiler.  Using YARV, you compile your code into bytecode (like JVM)  JVM compiles the bytecode with JIT compiler, Ruby interprets the bytecode
  • 13. Hey, Isn’t it too complex?
  • 14. Compilation (Cont.)  Why this extra compiler added from version 1.9?  Answer: Speed. A compiled program with YARV is much faster (~ 4.25 times) than traversing AST nodes.  Okay, Now what?  Answer: Now let’s taste the magic of Ruby. Thanks to “Matz”.  Enough! Why do we need this actually?  Isn’t it awesome to know how a language works internally?
  • 15. From, Dohatec Thanks, I’m Imtiaz Hossain Emu