summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/ext/object_spec.c
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-09-28 18:37:17 +0200
committerBenoit Daloze <eregontp@gmail.com>2022-09-28 18:37:17 +0200
commit31cf1bb5256314b69eae92673d3dd5815158ee91 (patch)
tree5ee049f751426794bfe47d0fa847f5621d3a039d /spec/ruby/optional/capi/ext/object_spec.c
parent5a1ab740fc287df8bf4038f19bd28bbb73e181b6 (diff)
Update to ruby/spec@1d9d5c6
Diffstat (limited to 'spec/ruby/optional/capi/ext/object_spec.c')
-rw-r--r--spec/ruby/optional/capi/ext/object_spec.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/ext/object_spec.c b/spec/ruby/optional/capi/ext/object_spec.c
index 967b355c4a..30ac44cf1f 100644
--- a/spec/ruby/optional/capi/ext/object_spec.c
+++ b/spec/ruby/optional/capi/ext/object_spec.c
@@ -393,6 +393,18 @@ static VALUE object_spec_rb_class_inherited_p(VALUE self, VALUE mod, VALUE arg)
return rb_class_inherited_p(mod, arg);
}
+static int foreach_f(ID key, VALUE val, VALUE ary) {
+ rb_ary_push(ary, ID2SYM(key));
+ rb_ary_push(ary, val);
+ return ST_CONTINUE;
+}
+
+static VALUE object_spec_rb_ivar_foreach(VALUE self, VALUE obj) {
+ VALUE ary = rb_ary_new();
+ rb_ivar_foreach(obj, foreach_f, ary);
+ return ary;
+}
+
static VALUE speced_allocator(VALUE klass) {
VALUE flags = 0;
VALUE instance;
@@ -508,6 +520,7 @@ void Init_object_spec(void) {
rb_define_method(cls, "speced_allocator?", speced_allocator_p, 1);
rb_define_method(cls, "custom_alloc_func?", custom_alloc_func_p, 1);
rb_define_method(cls, "not_implemented_method", rb_f_notimplement, -1);
+ rb_define_method(cls, "rb_ivar_foreach", object_spec_rb_ivar_foreach, 1);
}
#ifdef __cplusplus