How do you pass a block, written in C, to Ruby's rb_mod_refine?

60 Views Asked by At

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!

1

There are 1 best solutions below

3
Peter Camilleri On BEST ANSWER

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.