0

可以将 proc 转换为 Ruby 虚拟机序列,YARVInstructionSequence/SimpleDataFormat如下所示:

RubyVM::InstructionSequence.of(->x{x + 1}).to_a
# => ["YARVInstructionSequence/SimpleDataFormat", 2, 0, 1,
  {:arg_size=>1, :local_size=>2, :stack_max=>2},
  "block in irb_binding", "(irb)", nil, 2,
  :block, [:x], [1, [], 0, 0, -1, -1, 3],
  [
    [:redo, nil, :label_0, :label_9, :label_0, 0],
    [:next, nil, :label_0, :label_9, :label_9, 0]
  ],
  [
    :label_0, 2, [:trace, 256], [:trace, 1], [:getlocal_OP__WC__0, 2],
    [:putobject_OP_INT2FIX_O_1_C_],
    [:opt_plus, {:mid=>:+, :flag=>256, :orig_argc=>1, :blockptr=>nil}], :label_9,
    [:trace, 512], [:leave]
  ]
]

有没有办法将这种格式转换回以重建字符串"->x{x+1}"或类似字符串的源表达式?

格式在RDoc中解释如下:

文档1 文档2 文档3 doc4

4

0 回答 0