Jump to content

Ruby Programming/Reference/Objects/RubyVM

From Wikibooks, open books for an open world

RubyVM is (as noted) very VM dependent. Currently it is defined only for 1.9.x MRI.

RubyVM::InstructionSequence.disassemble

[edit | edit source]

Available on 1.9 only, this is basically a wrapper for yarv.

>> class A; def go; end; end
>> b = A.new.method(:go)
=> #
>> print RubyVM::InstructionSequence.disassemble b
== disasm: =======================
0000 trace 8 ( 1)
0002 putnil
0003 trace 16 ( 1)
0005 leave

I believe those trace methods represent calls to any Kernel#set_trace_func (or the C sibling to that ruby method).

Also note that with 1.9.2 you can pass in a proc.