steps involves into execution of ruby code

Whenever you run a Ruby script what happens beneath is truly amazing. Ruby rips your code apart into small pieces and then puts it back together in a different format… three times! Between the time you type “ruby” and start to see actual output on the console, your Ruby code has a long road to take, a journey involving a variety of different technologies, techniques and open source tools.

How can a computer language be smart enough to understand the
code you give it? What does this intelligence really consist of?
Let’s look at the journey your code takes…

In this post we’ll follow a journey of a simple ruby program that is lexed, parsed and compiled into bytecode. We’ll use the tools that Ruby gives us to spy on the interpreter every step of the way.

This article explains well.

YARV interpreter
YARV (Yet Another Ruby VM) is the Ruby interpreter introduced in Ruby version 1.9, replacing the original interpreter: MRI (Matz’s Ruby Interpreter).

Languages that use interpreters directly execute code without an intermediate compilation step. This means that Ruby does not first compile a program to an optimized machine language program, which compiled languages such as C, Rust and Go do.

> RubyVM::InstructionSequence.compile(‘”foo” + “bar”‘).to_a

=> [“YARVInstructionSequence/SimpleDataFormat”, 2, 6, 1, {:arg_size=>0, :local_size=>0, :stack_max=>2, :node_id=>4, :code_location=>[1, 0, 1, 13]}, “”, “”, “”, 1, :top, [], {}, [], [1, :RUBY_EVENT_LINE, [:putstring, “foo”], [:putstring, “bar”], [:opt_plus, {:mid=>:+, :flag=>16, :orig_argc=>1}, false], [:leave]]]

Leave a comment