0

I am looking for ruby implementation of compiled code loading in following python code:

global tuser, temail
tuser = **imp.load_compiled**('tuser', uplug)
temail = **imp.load_compiled**('temail', eplug)

Thanks.

1 Answers1

0

Use RubyVM::InstructionSequence: https://ruby-doc.org/core-2.6/RubyVM/InstructionSequence.html

Example: https://devtechnica.com/ruby-language/compile-ruby-code-to-binary-and-execute-it

# compiler.rb
source_code = File.open(ARGV[0], 'r')       # load the file from arguments
compiled_code = RubyVM::InstructionSequence.compile(source_code)
binary_code = compiled_code.to_binary
binary_file = File.open(ARGV[0].split('.').first + '.bin', 'w+')
binary_file.puts binary_code
binary_file.close

# exec.rb
executable_binary_code = File.open(ARGV[0], 'r').readlines.join('')
compiled_instruction_sequence = \
  RubyVM::InstructionSequence.load_from_binary(executable_binary_code)
compiled_instruction_sequence.eval
ruby compiler.rb fibonacci.rb
ruby exec.rb fibonacci.bin
go2null
  • 2,080
  • 1
  • 21
  • 17