Skip to content

Commit 78e266d

Browse files
committed
Clarify documentation for InstructionSequence#compile.
We incorrectly assumed that the `file` argument should be the file name and caused scoutapp/scout_apm_ruby#307 because exception backtrace did not contain correct path. This documentation clarifies the role of the different arguments and provides extra examples.
1 parent cef9ebf commit 78e266d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

iseq.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -1156,10 +1156,14 @@ rb_iseqw_new(const rb_iseq_t *iseq)
11561156
* Takes +source+, a String of Ruby code and compiles it to an
11571157
* InstructionSequence.
11581158
*
1159-
* Optionally takes +file+, +path+, and +line+ which describe the filename,
1160-
* absolute path and first line number of the ruby code in +source+ which are
1159+
* Optionally takes +file+, +path+, and +line+ which describe the file path,
1160+
* real path and first line number of the ruby code in +source+ which are
11611161
* metadata attached to the returned +iseq+.
11621162
*
1163+
* +file+ is used for `__FILE__` and exception backtrace. +path+ is used for
1164+
* +require_relative+ base. It is recommended these should be the same full
1165+
* path.
1166+
*
11631167
* +options+, which can be +true+, +false+ or a +Hash+, is used to
11641168
* modify the default behavior of the Ruby iseq compiler.
11651169
*
@@ -1168,6 +1172,14 @@ rb_iseqw_new(const rb_iseq_t *iseq)
11681172
* RubyVM::InstructionSequence.compile("a = 1 + 2")
11691173
* #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
11701174
*
1175+
* path = "test.rb"
1176+
* RubyVM::InstructionSequence.compile(File.read(path), path, File.expand_path(path))
1177+
* #=> <RubyVM::InstructionSequence:<compiled>@test.rb:1>
1178+
*
1179+
* path = File.expand_path("test.rb")
1180+
* RubyVM::InstructionSequence.compile(File.read(path), path, path)
1181+
* #=> <RubyVM::InstructionSequence:<compiled>@/absolute/path/to/test.rb:1>
1182+
*
11711183
*/
11721184
static VALUE
11731185
iseqw_s_compile(int argc, VALUE *argv, VALUE self)

0 commit comments

Comments
 (0)