summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/ext/array_spec.c
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/ext/array_spec.c')
-rw-r--r--spec/ruby/optional/capi/ext/array_spec.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/ext/array_spec.c b/spec/ruby/optional/capi/ext/array_spec.c
index afd6aeef15..628c4df9d7 100644
--- a/spec/ruby/optional/capi/ext/array_spec.c
+++ b/spec/ruby/optional/capi/ext/array_spec.c
@@ -162,6 +162,14 @@ static VALUE array_spec_rb_ary_shift(VALUE self, VALUE array) {
return rb_ary_shift(array);
}
+static VALUE array_spec_rb_ary_sort(VALUE self, VALUE array) {
+ return rb_ary_sort(array);
+}
+
+static VALUE array_spec_rb_ary_sort_bang(VALUE self, VALUE array) {
+ return rb_ary_sort_bang(array);
+}
+
static VALUE array_spec_rb_ary_store(VALUE self, VALUE array, VALUE offset, VALUE value) {
rb_ary_store(array, FIX2INT(offset), value);
@@ -188,6 +196,7 @@ static VALUE copy_ary(RB_BLOCK_CALL_FUNC_ARGLIST(el, new_ary)) {
return rb_ary_push(new_ary, el);
}
+#ifndef RUBY_VERSION_IS_4_0
static VALUE array_spec_rb_iterate(VALUE self, VALUE ary) {
VALUE new_ary = rb_ary_new();
@@ -195,11 +204,21 @@ static VALUE array_spec_rb_iterate(VALUE self, VALUE ary) {
return new_ary;
}
+#endif
+
+static VALUE array_spec_rb_block_call(VALUE self, VALUE ary) {
+ VALUE new_ary = rb_ary_new();
+
+ rb_block_call(ary, rb_intern("each"), 0, 0, copy_ary, new_ary);
+
+ return new_ary;
+}
static VALUE sub_pair(RB_BLOCK_CALL_FUNC_ARGLIST(el, holder)) {
return rb_ary_push(holder, rb_ary_entry(el, 1));
}
+#ifndef RUBY_VERSION_IS_4_0
static VALUE each_pair(VALUE obj) {
return rb_funcall(obj, rb_intern("each_pair"), 0);
}
@@ -211,16 +230,32 @@ static VALUE array_spec_rb_iterate_each_pair(VALUE self, VALUE obj) {
return new_ary;
}
+#endif
+
+static VALUE array_spec_rb_block_call_each_pair(VALUE self, VALUE obj) {
+ VALUE new_ary = rb_ary_new();
+
+ rb_block_call(obj, rb_intern("each_pair"), 0, 0, sub_pair, new_ary);
+
+ return new_ary;
+}
static VALUE iter_yield(RB_BLOCK_CALL_FUNC_ARGLIST(el, ary)) {
rb_yield(el);
return Qnil;
}
+#ifndef RUBY_VERSION_IS_4_0
static VALUE array_spec_rb_iterate_then_yield(VALUE self, VALUE obj) {
rb_iterate(rb_each, obj, iter_yield, obj);
return Qnil;
}
+#endif
+
+static VALUE array_spec_rb_block_call_then_yield(VALUE self, VALUE obj) {
+ rb_block_call(obj, rb_intern("each"), 0, 0, iter_yield, obj);
+ return Qnil;
+}
static VALUE array_spec_rb_mem_clear(VALUE self, VALUE obj) {
VALUE ary[1];
@@ -272,14 +307,21 @@ void Init_array_spec(void) {
rb_define_method(cls, "rb_ary_reverse", array_spec_rb_ary_reverse, 1);
rb_define_method(cls, "rb_ary_rotate", array_spec_rb_ary_rotate, 2);
rb_define_method(cls, "rb_ary_shift", array_spec_rb_ary_shift, 1);
+ rb_define_method(cls, "rb_ary_sort", array_spec_rb_ary_sort, 1);
+ rb_define_method(cls, "rb_ary_sort_bang", array_spec_rb_ary_sort_bang, 1);
rb_define_method(cls, "rb_ary_store", array_spec_rb_ary_store, 3);
rb_define_method(cls, "rb_ary_concat", array_spec_rb_ary_concat, 2);
rb_define_method(cls, "rb_ary_plus", array_spec_rb_ary_plus, 2);
rb_define_method(cls, "rb_ary_unshift", array_spec_rb_ary_unshift, 2);
rb_define_method(cls, "rb_assoc_new", array_spec_rb_assoc_new, 2);
+#ifndef RUBY_VERSION_IS_4_0
rb_define_method(cls, "rb_iterate", array_spec_rb_iterate, 1);
rb_define_method(cls, "rb_iterate_each_pair", array_spec_rb_iterate_each_pair, 1);
rb_define_method(cls, "rb_iterate_then_yield", array_spec_rb_iterate_then_yield, 1);
+#endif
+ rb_define_method(cls, "rb_block_call", array_spec_rb_block_call, 1);
+ rb_define_method(cls, "rb_block_call_each_pair", array_spec_rb_block_call_each_pair, 1);
+ rb_define_method(cls, "rb_block_call_then_yield", array_spec_rb_block_call_then_yield, 1);
rb_define_method(cls, "rb_mem_clear", array_spec_rb_mem_clear, 1);
rb_define_method(cls, "rb_ary_freeze", array_spec_rb_ary_freeze, 1);
rb_define_method(cls, "rb_ary_to_ary", array_spec_rb_ary_to_ary, 1);