Created
June 22, 2011 21:17
-
-
Save mattwildig/1041242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.o | |
*.so | |
*.bundle | |
Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mkmf' | |
$CFLAGS << " -Wall" | |
create_makefile('foo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
class Bar | |
def original_ruby_method | |
"original" | |
end | |
end | |
end | |
require 'foo.so' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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