Forum: Ruby Class object creation and scope

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 John Lam (Guest)
on 2005-12-17 05:32
(Received via mailing list)
It appears that class objects (created via are somewhat
I'm trying to write some code to inject some non-Ruby data into these
objects. I'm worried about what happens at GC time, so I need to use
Data_Wrap_Struct() to create the class objects so that I can register my
memory cleanup functions with Ruby.

However, this technique doesn't seem to work. If I try to create a class
object using:

Data_Wrap_Struct(rb_cClass, 0, ReleaseClassObject, my_data);

Ruby complains with a bizarre TypeError exception: "wrong argument type
Class (expected Class)".

I've tried some other workarounds involving the use of
rb_define_alloc_func(), which works fine for non class objects, but
seems to be something special about how Ruby handles class objects.

A secondary question: what's the lifetime of a class object in Ruby? Are
these things ever garbage collected?

2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 John Lam (Guest)
on 2005-12-17 06:11
(Received via mailing list)
I just took a look at rb_class_boot(), and it looks like I can't make a
class object a T_DATA type. Ugh.

So it looks like my only hope is that class objects are never GC'd ...
pointers here would be super-helpful.

This topic is locked and can not be replied to.