From: "Brett W. Denner" Date: 2001-07-13T02:07:47+09:00 Subject: [ruby-talk:17740] Ruby/C extension for module with nested classes I am trying to create a Ruby extension that consists of a module containing several classes. In my example, the module is called Fruit, and one of the classes is Apple. I would like use the module as follows: require 'Fruit' a = Fruit::Apple.new If I wanted to write the module and classes in Ruby, it would look like this: module Fruit class Apple def initialize end end end In my efforts to create an extension using C, my extconf.rb file looks like this: require 'mkmf' create_makefile('Fruit') and the C source file (called fruit.c) looks like this: #include "ruby.h" #include static VALUE s_init(VALUE self) { return self; } VALUE cFruit; void Init_Fruit() { cFruit = rb_define_module("Fruit"); fprintf(stderr, "Init_Fruit\n"); } VALUE cApple; void Init_Apple() { cApple = rb_define_class_under(cFruit, "Apple", rb_cObject); rb_define_method(cApple, "initialize", s_init, 0); fprintf(stderr, "Init_Apple\n"); } When I run "ruby extconf.rb" and "make", everything compiles just fine. However, when I try to use the module (using the sample Ruby code at the top) I get the following output: Init_Fruit ./test.rb:4: uninitialized constant Apple at Fruit (NameError) I realize that the Fruit::Apple.new syntax could be incorrect, but I've tried Fruit#Apple and Fruit.Apple, but nothing works. In each case, the Init_Apple subroutine is not being called. How do I modify my code to create an extension with for a module with nested classes? Thanks, Brett Denner -- Brett W. Denner Lockheed Martin Aeronautics Co. email: Brett.W.Denner@lmco.com PO Box 748, MZ 9332 phone: 817-935-1144 Fort Worth, TX 76101 fax: 817-935-1212