Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

How to create a Ruby extension in C in 43 seconds

By Peter Cooper / August 1, 2006

Less than two months ago, I wrote How to Create a Ruby Extension in C in under 5 minutes. Times have changed.

Zenspider, the master of all things Ruby crossed with C, picked up the gauntlet and, using RubyInline (previously covered here), has handed my proverbial ass back to me on a platter. All you have to have is the RubyInline library installed.

In just 43 seconds, you too could launch an editor, paste in this code, and check it out:

#!/usr/local/bin/ruby -w

require 'rubygems'
require 'inline'

class Example
  inline(:C) do |builder|
    builder.c "int test1() {
                 int x = 10;
                 return x;
               }"
  end
end

p Example.new.test1

No ruby.h? What ruby.h!? It's as easy as that.

Other Posts to Enjoy

Twitter Mentions