summaryrefslogtreecommitdiff
path: root/object.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 /object.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 'object.c')
-rw-r--r--object.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/object.c b/object.c
index 9243df5587..ef8a855dfb 100644
--- a/object.c
+++ b/object.c
@@ -1005,6 +1005,28 @@ rb_class_search_ancestor(VALUE cl, VALUE c)
*/
#define rb_obj_singleton_method_undefined rb_obj_dummy1
+/* Document-method: const_added
+ *
+ * call-seq:
+ * const_added(const_name)
+ *
+ * Invoked as a callback whenever a constant is assigned on the receiver
+ *
+ * module Chatty
+ * def self.const_added(const_name)
+ * super
+ * puts "Added #{const_name.inspect}"
+ * end
+ * FOO = 1
+ * end
+ *
+ * <em>produces:</em>
+ *
+ * Added :FOO
+ *
+ */
+#define rb_obj_mod_const_added rb_obj_dummy1
+
/*
* Document-method: extended
*
@@ -4419,6 +4441,7 @@ InitVM_Object(void)
rb_define_private_method(rb_cModule, "extended", rb_obj_mod_extended, 1);
rb_define_private_method(rb_cModule, "prepended", rb_obj_mod_prepended, 1);
rb_define_private_method(rb_cModule, "method_added", rb_obj_mod_method_added, 1);
+ rb_define_private_method(rb_cModule, "const_added", rb_obj_mod_const_added, 1);
rb_define_private_method(rb_cModule, "method_removed", rb_obj_mod_method_removed, 1);
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_mod_method_undefined, 1);