BSalunke
BSalunke

Reputation: 11727

How to get exact type of object in Ruby extended C++?

Hi. I'm working on a Ruby C++ extension, I have the following function, in which "self" object is either of structure type or of Exception type.

VALUE myFunction(VALUE self, VALUE args)
{
  // Some functon call and process on args argument
}

Now in the above function I need to know the exact type of object "self" (i.e. rb_eException or rb_cStruct), I tried using the following API,

if(Qtrue == rb_obj_is_kind_of(self, rb_eException))
{
   std::cout<<"self is of rb_eException type "<<std::endl;
}

like above for rb_cStruct, rb_cClass etc but I'm getting only Qtrue for "rb_cClass" type. How can I get the exact type of "self" object (i.e rb_cStruct or rb_eException)? Thanks in advance.

Upvotes: 2

Views: 189

Answers (1)

tadman
tadman

Reputation: 211560

You can get the class with rb_obj_class which would be the appropriate VALUE.

Upvotes: 1

Related Questions