[前][次][番号順一覧][スレッド一覧]

ruby-changes:58835

From: Samuel <ko1@a...>
Date: Tue, 19 Nov 2019 11:40:29 +0900 (JST)
Subject: [ruby-changes:58835] 78e266da1d (master): Clarify documentation for `InstructionSequence#compile`.

https://git.ruby-lang.org/ruby.git/commit/?id=78e266da1d

From 78e266da1dede1c81e634982e76a129c5720d80e Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Tue, 19 Nov 2019 11:40:00 +0900
Subject: Clarify documentation for `InstructionSequence#compile`.

We incorrectly assumed that the `file` argument should be the file name and
caused https://github.com/scoutapp/scout_apm_ruby/issues/307 because
exception backtrace did not contain correct path. This documentation
clarifies the role of the different arguments and provides extra
examples.

diff --git a/iseq.c b/iseq.c
index cb179d1..b7443a7 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1156,10 +1156,14 @@ rb_iseqw_new(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1156
  *  Takes +source+, a String of Ruby code and compiles it to an
  *  InstructionSequence.
  *
- *  Optionally takes +file+, +path+, and +line+ which describe the filename,
- *  absolute path and first line number of the ruby code in +source+ which are
+ *  Optionally takes +file+, +path+, and +line+ which describe the file path,
+ *  real path and first line number of the ruby code in +source+ which are
  *  metadata attached to the returned +iseq+.
  *
+ *  +file+ is used for `__FILE__` and exception backtrace. +path+ is used for
+ *  +require_relative+ base. It is recommended these should be the same full
+ *  path.
+ *
  *  +options+, which can be +true+, +false+ or a +Hash+, is used to
  *  modify the default behavior of the Ruby iseq compiler.
  *
@@ -1168,6 +1172,14 @@ rb_iseqw_new(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1172
  *     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>
+ *
  */
 static VALUE
 iseqw_s_compile(int argc, VALUE *argv, VALUE self)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]