[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

get the class of an instance

Elias Athanasopoulos

11/26/2003 8:42:00 PM

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,
--
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky




2 Answers

Tim Hunter

11/26/2003 9:51:00 PM

0

On Thu, 27 Nov 2003 05:42:22 +0900, Elias Athanasopoulos wrote:

> 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));

Elias Athanasopoulos

12/2/2003 6:54:00 PM

0

On Thu, Nov 27, 2003 at 06:52:11AM +0900, Tim Hunter wrote:
> On Thu, 27 Nov 2003 05:42:22 +0900, Elias Athanasopoulos wrote:
>
> > 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));

That was the trick. Thanx. Apologies for my delayed answer.

Regards,
--
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky