Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news.mixmin.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: Joel VanderWerf Newsgroups: comp.lang.ruby Subject: Re: Building extention with multiple classes Date: Fri, 29 Apr 2011 17:32:32 -0500 Organization: Service de news de lacave.net Lines: 23 Message-ID: <4DBB3C76.8020805@gmail.com> References: <3ec123b0b692087d2e4c8472a3ba1eb9@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1304118054 45840 65.111.164.187 (29 Apr 2011 23:00:54 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Fri, 29 Apr 2011 23:00:54 +0000 (UTC) In-Reply-To: <3ec123b0b692087d2e4c8472a3ba1eb9@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 382414 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <4DBB3C76.8020805@gmail.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3722 On 04/29/2011 02:39 PM, Richard Shinn wrote: > Hello, > > I have been successful at building a ruby extension that contains one > new class and now I would like to build multiple classes. I am wondering > what is the best way to do this. Take a look at the ext/ dir in ruby's source. For example, in socket.c: void Init_socket() { rb_eSocket = rb_define_class("SocketError", rb_eStandardError); rb_cBasicSocket = rb_define_class("BasicSocket", rb_cIO); This snippet defines two classes. Farther down you'll see the rb_define_method() calls to associate the C functions that implement methods, and also the C functions themselves. These functions can just as well be defined in separate .c files in the same dir. They will get found by extconf.rb (in the create_makefile call, IIRC).