Last Updated: September 09, 2019
·
1.534K
· citizen428

Looking at Ruby internals

While this may not be useful for day to day coding, if you plan on hacking Ruby itself or just are a very curious person, the following can be very interesting.

First, there's a way to dump the abstract syntax tree (AST) that Ruby creates while parsing your code:

ruby --dump parsetree file.rb

This can also be done programmatically:

require 'ripper'
code = << EOC
...
EOC

Ripper.sexp(code)

Alternatively you can dump the instructions that can be generated for YARV (Yet Another Ruby VM):

ruby --dump insns file.rb

Or from inside Ruby:

RubyVM::InstructionSequence.compile(code).disasm