Cameron
Cameron

Reputation: 651

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

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!

Upvotes: 1

Views: 59

Answers (1)

Peter Camilleri
Peter Camilleri

Reputation: 1912

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.

Upvotes: 1

Related Questions