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
Written by Michael Kohl
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#