【发布时间】:2020-08-30 17:28:22
【问题描述】:
我有 2 个 ruby 源文件,例如:
A.rb
require "B"
foo
B.rb
def foo()
..
end
现在我使用代码将 A 编译为字节码(Ruby v2.3.3):
byte_code = RubyVM::InstructionSequence.compile_file "A.rb"
File.binwrite "A.byte", byte_code.to_binary
当我运行字节码时:
byte_code_in_binary = IO.binread "A.byte"
instruction_from_byte_code = RubyVM::InstructionSequence.load_from_binary byte_code_in_binary
instruction_from_byte_code.eval
那么消息是:
.... in `require': cannot load such file -- B (LoadError)
如果我将 B.rb 编译为字节码,那么 A.byte 如何加载 B.byte ?还是有另一种方法可以将完整的 ruby 项目编译为字节码并运行? Jruby 或一些工具可以实现吗?谢谢。
【问题讨论】: