From: Logan Capaldo Date: 2006-06-28T05:13:56+09:00 Subject: Re: Define External Superclass in a extension On Jun 27, 2006, at 2:23 PM, Ceaser Larry wrote: > I'm trying to learn how to create a ruby extension. I've read the > pick axe book but I'm running into a problem understanding how to > get a reference to classes defined outside the ruby.h header. > > My problem is how do I reference the DBI::BaseDriver as a super > class to my object? > > In C I understand I can use the following to define a new class > > VALUE rb_cMyClass = rb_define_class("MyClass", rb_cObject) > > somehow I need to replace rb_cObject with a reference to the > DBI::BaseDriver like so > > VALUE rb_cMyClass = rb_define_class("MyClass", [DBI::BaseDriver]) > > Any help or nudge in the right direction would be appreciated. > > Thanks > Ceaser > See rb_const_get. It'll be something like rb_cMyClass = rb_define_class("MyClass", rb_const_get( rb_const_get(rb_cObject, intern("DBI")), intern("BaseDriver")));