Skip to content

Instantly share code, notes, and snippets.

@grahamlyons
Last active Sep 11, 2015
Embed
What would you like to do?
Create two files with Ruby VM bytecode instructions
def get_test_class(a_assignment)
test_class = <<-EOF
class T
attr_accessor(:a)
def initialize
@a = 42
end
def t(this_a=nil)
if this_a
#{a_assignment}
end
a
end
end
EOF
end
iseq_without_assignment = RubyVM::InstructionSequence.compile(get_test_class(nil))
iseq_with_assignment = RubyVM::InstructionSequence.compile(get_test_class('a = this_a'))
File.open('iseq_without_assignment.txt', 'w+') do |f|
f.write(iseq_without_assignment.disassemble)
end
File.open('iseq_with_assignment.txt', 'w+') do |f|
f.write(iseq_with_assignment.disassemble)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment