get the class of an instance

  • Thread starter Elias Athanasopoulos
  • Start date
E

Elias Athanasopoulos

Hello!

I want to get the class of an object through the Ruby C API.
Actually, I want what foo.class does.

I tried:

foo = STR2CSTR(rb_iv_get(self, "@class"));

but it doesn't work.

I also tried:

foo = rb_obj_as_string(rb_obj_class(self));

which it seems to work, but it produces a strange output:

% ruby gen.rb
gen.rb:11: warning:

Foo

(Notice the '\n's after warning:)

Is there another better way? (Okay I can replace '\n's but it
seems to me that I'm following the wrong way).

Regards,
 
T

Tim Hunter

Hello!

I want to get the class of an object through the Ruby C API. Actually, I
want what foo.class does.

VALUE foo;
char *name;

name = rb_class2name(CLASS_OF(foo));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top