SlideShare a Scribd company logo
1 of 16
Download to read offline
Digging into Ruby guts
For why?
●

Become a better developer
–

If you know internals of your language, you'll use it
more efficient

–

If you will understand more, you can help
community

●

Improve your knowledge of computer science

●

Just for fun, you know
How Ruby reads your code
How Ruby executes your code
What is the tokens?
10.times { |n| puts n }
●

tINTEGER

●

tIDENTIFIER

●

keyword_do, |tIDENTIFIER|
Ripper class — Ruby lexical analyzer
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ripper/rdoc/Ripper.html
How it parses?
●

Bison (Yacc descendant)

●

Samples of grammar rules

●

Ruby code roadmap:
–

Ruby source code

–

Tokens

–

AST Nodes

–

YARV Instructions
And we need to go deeper
What the hell is YARV?
YARV (Yet Another Ruby Virtual Machine)
–

Stack-oriented virtual machine

–

Developed by Koichi Sasada (mostly)

–

Finally, it's double stack machine

–

Tracing of ruby code using YARV

–

Well-documented, really ( スタックに self をプッ
シュする )
How it works?

Little workshop
RubyVM module
●

Well-documented, you know, as before ( スタッ
クに self をプッシュする )

●

http://www.ruby-doc.org/core-2.0.0/RubyVM.html

●

Container for RubyVM::InstructionSequence
Benefits
●

Speed up your templates by precompiling

●

Use functional style programming

●

Trace your program if bug is hard to find
Bytecode Compilation
Rubinius is not needed anymore. At least,
runtime.
(little demonstration)
https://github.com/haml/haml/issues/674
https://gist.github.com/Paxa/321be47319327e5e7058
Tail Call Optimization

Just for functional programming addicts
(another little demonstration)
Where to find more?
●

Ruby under the microscope

●

Ruby sources

●

http://lmgtfy.com/?q=RubyVM

●

https://www.ruby-forum.com/forum/ruby-core

●

http://rxr.whitequark.org/mri/source/iseq.c
We are hiring. Take a contacts ;)
Mikhail Bortnyk
vessimir@gmail.com
Skype: mikhail.bortnyk
https://github.com/vessi/rubymeditation3_yarv

More Related Content

Similar to Digging into Ruby Guts

Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
knoppix
 
Adventures of java developer in ruby world
Adventures of java developer in ruby worldAdventures of java developer in ruby world
Adventures of java developer in ruby world
Orest Ivasiv
 
Forget Ruby. Forget CoffeeScript. Do SOA
Forget Ruby. Forget CoffeeScript. Do SOAForget Ruby. Forget CoffeeScript. Do SOA
Forget Ruby. Forget CoffeeScript. Do SOA
Michał Łomnicki
 
Ruby in prijatelji
Ruby in prijateljiRuby in prijatelji
Ruby in prijatelji
Oto Brglez
 

Similar to Digging into Ruby Guts (20)

Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
Adventures of java developer in ruby world
Adventures of java developer in ruby worldAdventures of java developer in ruby world
Adventures of java developer in ruby world
 
Scala days mizushima
Scala days mizushimaScala days mizushima
Scala days mizushima
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
The story of language development
The story of language developmentThe story of language development
The story of language development
 
Ruby
RubyRuby
Ruby
 
Forget Ruby. Forget CoffeeScript. Do SOA
Forget Ruby. Forget CoffeeScript. Do SOAForget Ruby. Forget CoffeeScript. Do SOA
Forget Ruby. Forget CoffeeScript. Do SOA
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
 
Ruby an overall approach
Ruby an overall approachRuby an overall approach
Ruby an overall approach
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
Ruby Beyond Rails
Ruby Beyond RailsRuby Beyond Rails
Ruby Beyond Rails
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Ruby in prijatelji
Ruby in prijateljiRuby in prijatelji
Ruby in prijatelji
 
Ruby Class 1
Ruby Class 1Ruby Class 1
Ruby Class 1
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developers
 
sl slides-unit-1.pptx
sl slides-unit-1.pptxsl slides-unit-1.pptx
sl slides-unit-1.pptx
 
Code rippa
Code rippaCode rippa
Code rippa
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Digging into Ruby Guts