murgatroid99
murgatroid99

Reputation: 20297

How can I check whether a VALUE is a Proc in a Ruby C extension?

I have a method in a Ruby C extension that takes a Proc as an argument, and I would like to verify that the argument is the correct type, i.e. I would like to do the equivalent of arg.is_a?(Proc) but in the C code. I found the CheckType macro, but it looks like Proc is not one the list of built in types that it can check against. So, how can I do this?

Upvotes: 2

Views: 322

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84132

Those macros correspond to the different types of RVALUE. To check against arbitrary classes, you use rb_obj_is_kind_of which is the C function that sits behind is_a?:

rb_obj_is_kind_of(some_obj, rb_cProc);

Note that this returns QTrue/QFalse. You should also be able to use rb_obj_is_proc

Upvotes: 1

Related Questions