Writing a Ruby Extension Tutorial
I had a pressing need recently for a Ruby C extension, and whilst I was building it I thought it would be a good idea to document what I did. Thus, I set up a guide that showed my steps as I went through the process.
The guide is not yet complete, but it’s complete enough to be a good start for someone who’s interested in how to do this.
The guide is here: http://www.tarkblog.org/rubyextension/
If anyone wants to take the time to sit down and make sure I didn’t make any glaring mistakes in writing it up, I would appreciate it. It is more meant as a catalog of my thoughts as I was going through the process and isn’t a step-by-step guide. My extension works, but that’s not to say that I didn’t fat finger something or forget a step or two as I wrote it up. Comments/concerns/questions can be sent to caleb-at-aei-hyphen-tech-dot-com.
December 5th, 2005 at 12:43 pm
Thank you!!!!!
December 5th, 2005 at 7:57 pm
I’m curious about why you decided to define a “new” method instead of defining an allocation function with rb_define_alloc_func and defining “initialize”? I believe the 2nd approach is recommended for extensions in 1.8.x. See for example string.c in the Ruby source files.
December 6th, 2005 at 8:59 am
Not for any good reason. I wrote a good portion of it on the road and didn’t have my Pickaxe with me, but I did have an old extension I was referencing to find some method names from. That’s probably where I picked it up. I may go back and change it, now that I see what you’re talking about.