From: Joel VanderWerf Date: 2002-09-08T03:48:47+09:00 Subject: Re: Ruby aesthetics William Djaja Tjokroaminata wrote: ... > In my case, as I develop in C, I have put a lot of data members in C > struct instead of Ruby data hash, in which case name collision is > impossible. I still have not solved the puzzle of how to best create the > C's struct so that we can mimic the Ruby object inheritance on the C > side. Probably the solution is to combine Ruby and C++ for large projects > where C++ takes much of the load and Ruby is used more as an advance, > programmable, interface? There's one solution in the CShadow module in my cgen package on RAA. If you mix this guy into your base class, you can declare C attributes (with or without readers and writers) from your Ruby code. The attributes declared in a subclass X are inherited in any class Y < X, and they are allocated using Data_Make_Struct. In addition to accessors (which handle type checking and conversion), the mixin will generate C code for mark/free, marshalling, and initialization (if you need it). You can add your own attribute classes. You can define methods using "inline" C code, with a handy interface to Ruby's rb_scan_args(). When you've finished with all your declarations, just call #commit on your class (which compiles and loads the dyn lib) and then you can instantiate and use the objects.