Accessing a struct created within a C extension

Hi all,

Ruby 1.8.2

In pure Ruby I can do this:

class File
TStruct = Struct.new("TStruct",:bar,:baz)
end

t = File::TStruct.new("hello","world")

How do I achieve the equivalent from within a C extension? I have
this:

void Init_file(){
VALUE tStruct = rb_struct_define("TStruct","bar","baz",0);
}

I am unable to access this from within Ruby, however. I also tried
declaring it as "File::TStruct", but Ruby complained with a NameError.
So, how do I declare a struct "under" a specific class?

Regards,

Dan

class File
TStruct = Struct.new("TStruct",:bar,:baz)
end

t = File::TStruct.new("hello","world")

Probably I've not understood

uln% cat a.c
#include <ruby.h>

void Init_a()
{
    rb_const_set(rb_cFile, rb_intern("TStruct"),
                 rb_struct_define("TStruct","bar","baz",0));
}

uln%

uln% ruby -ra -e 'p File::TStruct.new("hello","world")'
#<struct Struct::TStruct bar="hello", baz="world">
uln%

Guy Decoux

ts wrote:

> class File
> TStruct = Struct.new("TStruct",:bar,:baz)
> end

> t = File::TStruct.new("hello","world")

Probably I've not understood

uln% cat a.c
#include <ruby.h>

void Init_a()
{
    rb_const_set(rb_cFile, rb_intern("TStruct"),
                 rb_struct_define("TStruct","bar","baz",0));
}

uln%

uln% ruby -ra -e 'p File::TStruct.new("hello","world")'
#<struct Struct::TStruct bar="hello", baz="world">
uln%

Guy Decoux

That's it. Thanks Guy.

Dan.