Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Writing Your Own Ruby Extension With C

By Peter Cooper / January 25, 2007

In case the title of this post is giving you deja-vu, we've looked at "How To Create A Ruby Extension In C" before at Ruby Inside. We've also looked at using RubyInline to make the process even faster by not having to write a specialized C extension.

Despite this, Wim Vander Schelden has written such a detailed and interesting guide called "Writing Your Own Ruby Extension With C" that it's a must-read if this area interests you, especially since it goes far beyond what was covered in our previous articles.


  1. juantar says:

    Also check the excellent Ruby Extension utility classes on Gaffer on Games ( It is a really nice toolkit to create your C++ ruby objects easily.

  2. Daniel Berger says:

    His comments on arrays are completely wrong. You do not need to declare an extra RARRAY struct and then assign to it, as he does in the greet function. If the user passed an array, then that's what you get. Or, you can force the issue by setting the number of arguments in the function declaration to -2 to get splat-like behavior.

    If an array is passed as the argument, just use RARRAY(arg)->ptr. To get at a specific index, just use RARRAY(arg)->ptr[i].


Other Posts to Enjoy

Twitter Mentions