summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-05-22 12:04:01 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-01-14 11:30:07 +0100
commit8d05047d72d0a4b97f57b23bddbca639375bbd03 (patch)
treed3caaf18c73b9f3423402162626c5dc5abc4965e /variable.c
parent53a4e101465a4d2ae38ea3bfd3cb7dd3c9f12f61 (diff)
Add a Module#const_added callback
[Feature #17881] Works similarly to `method_added` but for constants. ```ruby Foo::BAR = 42 # call Foo.const_added(:FOO) class Foo::Baz; end # call Foo.const_added(:Baz) Foo.autoload(:Something, "path") # call Foo.const_added(:Something) ```
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4521
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/variable.c b/variable.c
index eaad6eb497..ebfbf017c1 100644
--- a/variable.c
+++ b/variable.c
@@ -3102,6 +3102,15 @@ set_namespace_path(VALUE named_namespace, VALUE namespace_path)
RB_VM_LOCK_LEAVE();
}
+static void
+const_added(VALUE klass, ID const_name)
+{
+ if (GET_VM()->running) {
+ VALUE name = ID2SYM(const_name);
+ rb_funcallv(klass, idConst_added, 1, &name);
+ }
+}
+
void
rb_const_set(VALUE klass, ID id, VALUE val)
{
@@ -3166,6 +3175,7 @@ rb_const_set(VALUE klass, ID id, VALUE val)
}
}
}
+ const_added(klass, id);
}
static struct autoload_data_i *