How to get Ruby object class in C?

I have a function that processes two types: NVector and NMatrix ; the first is from the last. This function is mainly a specialized copy constructor. I want it to return an object of the same type as the one it was called on, so NVector returns NVector , not NMatrix .

 static VALUE nm_init_modifiedcopy(VALUE self) { // ... some code ... // formerly, I had cNMatrix where klass is. But it could also be cNVector! return Data_Wrap_Struct(klass, mark_func, delete_func, unwrapped_self_copy); } 

How to get object class property to go to Data_Wrap_Struct ?

+4
source share
1 answer

Like a clock, as soon as I ask a question about Stackoverflow, I find the answer.

Macro CLASS_OF .

 static VALUE nm_init_modifiedcopy(VALUE self) { // ... some code ... return Data_Wrap_Struct(CLASS_OF(self), mark_func, delete_func, unwrapped_self_copy); } 
+3
source

All Articles