Last active
April 28, 2018 05:41
-
-
Save tzmfreedom/47c4cf54cf8c23aaa7dadd5609ea40a8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# Write loaded ruby file | |
File.write('./loaded_file.rb', 'puts :hello') | |
# load file and write iseq file | |
iseq = RubyVM::InstructionSequence.compile_file('./loaded_file.rb') | |
File.write('./loaded_file.yarb', iseq.to_binary) | |
# define load_iseq | |
class RubyVM::InstructionSequence | |
def self.load_iseq(fname) | |
b = File.read('./loaded_file.yarb') | |
RubyVM::InstructionSequence.load_from_binary(b) | |
end | |
end | |
TracePoint.trace(:line) do |tp| | |
puts "file: #{tp.path}, line: #{tp.lineno}" if tp.path =~ /loaded_file/ | |
end | |
load './loaded_file.rb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment