-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
respect current frame of
rb_eval_string
`self` is nearest Ruby method's `self`. If there is no ruby frame, use toplevel `self` (`main`). https://bugs.ruby-lang.org/issues/18780
- Loading branch information
Showing
4 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "ruby/ruby.h" | ||
|
||
static VALUE | ||
eval_string(VALUE self, VALUE str) | ||
{ | ||
return rb_eval_string(StringValueCStr(str)); | ||
} | ||
|
||
void | ||
Init_eval(void) | ||
{ | ||
rb_define_global_function("rb_eval_string", eval_string, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'mkmf' | ||
create_makefile('-test-/eval') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: false | ||
require 'test/unit' | ||
require "-test-/eval" | ||
|
||
class EvalTest < Test::Unit::TestCase | ||
def test_rb_eval_string | ||
a = 1 | ||
assert_equal [self, 1, __method__], rb_eval_string(%q{ | ||
[self, a, __method__] | ||
}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters