Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View .gitignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "ruby.h"
 
static VALUE Foo;
static VALUE Bar;
 
static VALUE
print_string(VALUE self, VALUE string) {
printf("%s\n", StringValuePtr(string));
return Qnil;
}
 
void Init_foo() {
Foo = rb_define_module("Foo");
Bar = rb_define_class_under(Foo, "Bar", rb_cObject);
rb_define_method(Bar, "print_string", print_string, 1);
}
View .gitignore
1 2 3 4 5
require 'mkmf'
 
$CFLAGS << " -Wall"
 
create_makefile('foo')
View .gitignore
1 2 3 4 5 6 7 8 9
module Foo
class Bar
def original_ruby_method
"original"
end
end
end
 
require 'foo.so'
View .gitignore
1 2 3 4 5 6 7 8 9 10
$:.unshift 'lib'
$:.unshift 'ext'
 
require 'foo'
 
bar = Foo::Bar.new
 
bar.print_string "hello" #defined in C (bar.c)
 
puts bar.original_ruby_method #defined in Ruby (foo.rb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.