I am trying to define a class inside a module with the Ruby C API. However, as I saw this done all over the network, it does not seem to work for me. In particular, a top-level module is created, but the class cannot be found inside the module. Here is my C file:
#include <ruby.h> static VALUE mTree; static VALUE cNode; VALUE hello_world(VALUE klass) { return rb_str_new2("hello world"); } void Init_tree() { mTree = rb_define_module("Tree"); cNode = rb_define_class_under(mTree, "Node", rb_cObject); rb_define_method(cNode, "hello_world", hello_world, 0); }
Here is my extconf.rb:
require 'mkmf' create_makefile('tree')
Here is my test script:
require 'tree' puts Tree
Does anyone help?
source share