Post by Peter Cooper on August 1st, 2006

How to create a Ruby extension in C in 43 seconds

Similar Posts
Popular Posts
Jobs

View All Jobs | Post a Job

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.

[Post to Twitter] Tweet This

Comments are closed.