本文簡要介紹ruby語言中 RubyVM::InstructionSequence.compile
的用法。
用法
compile(source[, file[, path[, line[, options]]]]) → iseq
new(source[, file[, path[, line[, options]]]]) → iseq
獲取 source
,一個 Ruby 代碼的 String
並將其編譯為 InstructionSequence
。
可選地采用 file
、 path
和 line
,它們說明了 source
中 ruby 代碼的文件路徑、真實路徑和第一行號,它們是附加到返回的 iseq
的元數據。
file
用於“__FILE__”和異常回溯。 path
用於require_relative
基礎。建議這些應該是相同的完整路徑。
options
可以是 true
、 false
或 Hash
,用於修改 Ruby iseq 編譯器的默認行為。
有關有效編譯選項的詳細信息,請參閱 ::compile_option=
。
RubyVM::InstructionSequence.compile("a = 1 + 2")
#=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
path = "test.rb"
RubyVM::InstructionSequence.compile(File.read(path), path, File.expand_path(path))
#=> <RubyVM::InstructionSequence:<compiled>@test.rb:1>
path = File.expand_path("test.rb")
RubyVM::InstructionSequence.compile(File.read(path), path, path)
#=> <RubyVM::InstructionSequence:<compiled>@/absolute/path/to/test.rb:1>
相關用法
- Ruby InstructionSequence.compile_file用法及代碼示例
- Ruby InstructionSequence.base_label用法及代碼示例
- Ruby InstructionSequence.disasm用法及代碼示例
- Ruby InstructionSequence.first_lineno用法及代碼示例
- Ruby InstructionSequence.of用法及代碼示例
- Ruby InstructionSequence.path用法及代碼示例
- Ruby InstructionSequence.label用法及代碼示例
- Ruby InstructionSequence.absolute_path用法及代碼示例
- Ruby InstructionSequence.disassemble用法及代碼示例
- Ruby InstructionSequence.eval用法及代碼示例
- Ruby Installer.install用法及代碼示例
- Ruby Installer.shebang用法及代碼示例
- Ruby Inspector.def_inspector用法及代碼示例
- Ruby Inspector類用法及代碼示例
- Ruby Integer.nobits?用法及代碼示例
- Ruby Integer lcm()用法及代碼示例
- Ruby Integer.self >=用法及代碼示例
- Ruby Integer.self >>用法及代碼示例
- Ruby Integer.next用法及代碼示例
- Ruby Integer.self ** numeric用法及代碼示例
- Ruby Integer integer?用法及代碼示例
- Ruby Integer.truncate用法及代碼示例
- Ruby Integer digits用法及代碼示例
- Ruby Integer divmod()用法及代碼示例
- Ruby Inflate.inflate用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 InstructionSequence.compile。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。