From: Shan-leung Maverick WOO Date: 2001-07-05T07:36:12+09:00 Subject: [ruby-talk:17254] extension and GC Hello, I am writing an extension X in C. It creates a new class which inherits from Hash. So in Init_X(), instead of passing rb_cObject to rb_define_class, I used rb_cHash. Here comes the two questions: 1. When the user creates the object, I want my own new routine to be called first. I do this by defining a singleton method "new" mapping to my C function X_new(). In my case, I believe I need to call super because Ruby has to construct the hash. So I called: rb_enable_super(rb_cHash, "new"); rb_call_super(argc, argv); But the first line already generates an error: > in `new': undefined method `new' for class `Hash' (NameError) What's the correct way to call rb_enable_super? 2. In X_new(), I also allocated some memory. But since I am not wrapping a structure, I don't know when to free the memory. Perhaps I am just plain wrong extending Hash this way? And if this helps: I am actually using Ruby as an extension language to my app and so I want to create a "conf" object which is a Ruby hash with all its existing methods and some of my own methods. That's why when I defined the class I used rb_cHash as the parent (so that I get all the existing methods). Thanks! -- All the best, Maverick Woo