Skip to content

Instantly share code, notes, and snippets.

@tzmfreedom
Last active April 28, 2018 05:41
Show Gist options
  • Save tzmfreedom/47c4cf54cf8c23aaa7dadd5609ea40a8 to your computer and use it in GitHub Desktop.
Save tzmfreedom/47c4cf54cf8c23aaa7dadd5609ea40a8 to your computer and use it in GitHub Desktop.
#!/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