summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorSatoshi Tagomori <s-tagomori@sakura.ad.jp>2025-10-31 23:38:16 +0900
committerSatoshi Tagomori <tagomoris@gmail.com>2025-11-03 02:06:11 +0900
commite89eecceafea3f8834c6fc4cdd74a7812591cae5 (patch)
treeee8e872cf9ea3bd30c11b57ec0bbb71c52decd7a /class.c
parentbc77a11bd845e4c3d79b990c196fedca37e9ab0b (diff)
No need to call rb_define_class/module_under_id
Classes/modules defined in a namespace are defined under ::Object as usual (as without namespaces), and it'll be set into the const_tbl of ::Object. In namespaces, namespace objects' const_tbl is equal to the one of ::Object. So constants of ::Object are just equal to constants of the namespace. That means, top level classes/modules in a namespace can be referred as namespace::KlassName without calling rb_define_class_under_id().
Diffstat (limited to 'class.c')
-rw-r--r--class.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/class.c b/class.c
index 5e50a281d9..a4249425a1 100644
--- a/class.c
+++ b/class.c
@@ -1605,13 +1605,8 @@ VALUE
rb_define_class(const char *name, VALUE super)
{
VALUE klass;
- ID id;
- const rb_namespace_t *ns = rb_current_namespace();
+ ID id = rb_intern(name);
- id = rb_intern(name);
- if (NAMESPACE_OPTIONAL_P(ns)) {
- return rb_define_class_id_under(ns->ns_object, id, super);
- }
if (rb_const_defined(rb_cObject, id)) {
klass = rb_const_get(rb_cObject, id);
if (!RB_TYPE_P(klass, T_CLASS)) {
@@ -1723,13 +1718,8 @@ VALUE
rb_define_module(const char *name)
{
VALUE module;
- ID id;
- const rb_namespace_t *ns = rb_current_namespace();
+ ID id = rb_intern(name);
- id = rb_intern(name);
- if (NAMESPACE_OPTIONAL_P(ns)) {
- return rb_define_module_id_under(ns->ns_object, id);
- }
if (rb_const_defined(rb_cObject, id)) {
module = rb_const_get(rb_cObject, id);
if (!RB_TYPE_P(module, T_MODULE)) {