Skip to content

Instantly share code, notes, and snippets.

@hugoabonizio
Created October 15, 2016 20:28
Show Gist options
  • Save hugoabonizio/1e90b6871cd29ccf7768818c1bf188fc to your computer and use it in GitHub Desktop.
Save hugoabonizio/1e90b6871cd29ccf7768818c1bf188fc to your computer and use it in GitHub Desktop.
Load precompiled ruby file
def requir(path)
source = "#{path}.rb"
compiled = "#{source}c"
if File.exists? compiled
bin = File.binread compiled
bytecode = RubyVM::InstructionSequence.load_from_binary(bin)
elsif File.exist? source
bytecode = RubyVM::InstructionSequence.compile_file(source)
File.binwrite compiled, bytecode.to_binary
else
message = "File not found! #{File.expand_path(source)}"
raise message
end
bytecode.eval
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment