« Return to Thread: c extension, classes and subclasses

c extension, classes and subclasses

by Rolando Abarca-2 :: Rate this Message:

Reply to Author | View in Thread

I have a few doubts about how the init mechanism in ruby1.9 (I'm  
working with it right now) works. I have a some classes and  
subclasses, all defined inside a ruby extension, the base class  
defines it's +new+ method like this:

rb_define_singleton_method(rb_cMyClass, "new", rb_cMyClass_s_new, -1);

This is the +new+ method:

VALUE rb_cMyClass_s_new(int argc, VALUE *argv, VALUE klass) {
        void *node;
        my_struct *ptr;
        ...
        VALUE obj = Data_Make_Struct(klass, my_struct, 0, custom_free, ptr);
        rb_obj_call_init(obj, argc, argv);
        return obj;
}

and every subclass defines a +new+ method just like that. The thing is:
Does rb_obj_call_init calls the superclass' new method?
Is this The Right Way(tm) to define/initialise classes and subclasses?

Thanks!
--
Rolando Abarca M.





 « Return to Thread: c extension, classes and subclasses