Perhaps more generally, how do you pass a block, written in C, to another C function that accepts a block? I know I can do something like this:
VALUE refine_foobar(VALUE block_arg, VALUE data, int argc, VALUE* argv) {
// block code here
return Qnil;
}
void Init_mything() {
VALUE mod = rb_define_module("Foobar");
rb_block_call(mod, rb_intern("refine"), 0, NULL, refine_foobar, Qnil);
}
but I feel like there has to be a way to call rb_mod_refine
directly instead of going through rb_block_call
.
Any ideas? Thanks!
In current usage, refinements are applied to modules. It's right there in the method's name.
AFAIK, it does not directly work with blocks.
The only way I can see this working is to create a "C" method in a module and then use ruby code to apply that module as a refinement in the conventional manner.