如何在C中获得Ruby对象的类?
我有一个处理两种类型的函数:如何在C中获得Ruby对象的类?,c,ruby,C,Ruby,我有一个处理两种类型的函数:NVector和NMatrix;前者源自后者。此函数基本上是一个专门的复制构造函数。我希望它返回与调用它的对象类型相同的对象,因此,NVector返回NVector,而不是NMatrix static VALUE nm_init_modifiedcopy(VALUE self) { // ... some code ... // formerly, I had cNMatrix where klass is. But it could also be cNV
NVector
和NMatrix
;前者源自后者。此函数基本上是一个专门的复制构造函数。我希望它返回与调用它的对象类型相同的对象,因此,NVector
返回NVector
,而不是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);
}
如何将对象的class属性传递到
数据包装结构
?就像时钟一样,只要我问一个关于Stackoverflow的问题,我就会找到答案
宏是的类
static VALUE nm_init_modifiedcopy(VALUE self) {
// ... some code ...
return Data_Wrap_Struct(CLASS_OF(self), mark_func, delete_func, unwrapped_self_copy);
}
“就像钟表一样,只要我问一个关于Stackoverflow的问题,我就会找到答案。”我们从Dorothy身上学到了什么?:-)在允许的情况下给自己选择的答案。我认为被接受的方法是rb_class_of(class_of simply is a macro by the function)