Last active
September 11, 2015 10:34
-
-
Save grahamlyons/b8487540dc283b38b4f7 to your computer and use it in GitHub Desktop.
Create two files with Ruby VM bytecode instructions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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