Two months ago, I wrote How to Create a Ruby Extension in C in under 5 minutes. But times have changed!
2012 update: Just tested and this all works in Ruby 1.9.3 almost six years later!
Zenspider, master of all things “Ruby + C”, picked up the gauntlet and used RubyInline (previously covered here) to hand my proverbial ass back to me on a platter. All you have to have is gem install RubyInline and.. 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? Read More