data := GoStruct{} return C.VALUE(ruby.NewGoStruct(ruby.VALUE(klass), unsafe.Pointer(&data))) } //export Init_example func Init_example() { rb_mExample := ruby.RbDefineModule("Example") // Create Example::GoStruct class rb_cGoStruct := ruby.RbDefineClassUnder(rb_mExample, "GoStruct", ruby.VALUE(C.rb_cObject)) ruby.RbDefineAllocFunc(rb_cGoStruct, C.go_struct_alloc) ruby.RbDefineMethod(rb_cGoStruct, "set", C.rb_example_go_struct_set, 2) ruby.RbDefineMethod(rb_cGoStruct, "get", C.rb_example_go_struct_get, 0) } https://pkg.go.dev/github.com/ruby-go-gem/go-gem-wrapper/ruby#NewGoStruct