summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-03-16 19:29:57 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-04-05 01:33:08 +0900
commit58918788abd63901588e4aa1e39b5c057321c10a (patch)
tree617721fc3c0bdca58942c83b9af95eec0be02ce5 /eval.c
parentef19234b1008508cb04048c815088b9359c9d2b6 (diff)
[Bug #20342] Consider wrapped load in `main` methods
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/eval.c b/eval.c
index 382d9fb5c8..e8da342ac6 100644
--- a/eval.c
+++ b/eval.c
@@ -1782,6 +1782,16 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
return obj;
}
+VALUE
+rb_top_main_class(const char *method)
+{
+ VALUE klass = GET_THREAD()->top_wrapper;
+
+ if (!klass) return rb_cObject;
+ rb_warning("main.%s in the wrapped load is effective only in wrapper module", method);
+ return klass;
+}
+
/*
* call-seq:
* include(module, ...) -> self
@@ -1794,13 +1804,7 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
static VALUE
top_include(int argc, VALUE *argv, VALUE self)
{
- rb_thread_t *th = GET_THREAD();
-
- if (th->top_wrapper) {
- rb_warning("main.include in the wrapped load is effective only in wrapper module");
- return rb_mod_include(argc, argv, th->top_wrapper);
- }
- return rb_mod_include(argc, argv, rb_cObject);
+ return rb_mod_include(argc, argv, rb_top_main_class("include"));
}
/*