1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/-test-/enumerator_kw/enumerator_kw.c
Jeremy Evans 3073404e74 Add rb_enumeratorize_with_size_kw and related macros
Currently, there is not a way to create a sized enumerator in C
with a different set of arguments than provided by Ruby, and
correctly handle keyword arguments.  This function allows that.

The need for this is fairly uncommon, but it occurs at least in
Enumerator.produce, which takes arugments from Ruby but calls
rb_enumeratorize_with_size with a different set of arguments.
2019-09-30 07:06:42 -07:00

21 lines
612 B
C

#include <ruby.h>
static VALUE
enumerator_kw(int argc, VALUE *argv, VALUE self)
{
VALUE obj, opt, enum_args[4];
enum_args[0] = Qnil;
enum_args[1] = Qnil;
rb_scan_args(argc, argv, "01*:", enum_args, enum_args+1, &opt);
enum_args[3] = self;
enum_args[2] = opt;
RETURN_SIZED_ENUMERATOR_KW(self, 4, enum_args, 0, RB_NO_KEYWORDS);
return rb_yield_values_kw(4, enum_args, RB_NO_KEYWORDS);
}
void
Init_enumerator_kw(void) {
VALUE module = rb_define_module("Bug");
module = rb_define_module_under(module, "EnumeratorKw");
rb_define_method(module, "m", enumerator_kw, -1);
}