Created
October 15, 2016 20:28
-
-
Save hugoabonizio/1e90b6871cd29ccf7768818c1bf188fc to your computer and use it in GitHub Desktop.
Load precompiled ruby file
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 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