go-gem-wrapper is a wrapper for creating Ruby native extension in Go
- Go
 - Ruby
 
At first, patch to make a gem into a Go gem right after bundle gem
Please also add the following depending on the CI you are using.
e.g.
- uses: actions/setup-go@v5
  with:
    go-version-file: ext/GEM_NAME/go.modFor example, consider the following Ruby method implemented in Go
module Example
  def self.sum(a, b)
    a + b
  end
end// ext/GEM_NAME/GEM_NAME.go
//export rb_example_sum
func rb_example_sum(_ C.VALUE, a C.VALUE, b C.VALUE) C.VALUE {
	aLong := ruby.NUM2LONG(ruby.VALUE(a))
	bLong := ruby.NUM2LONG(ruby.VALUE(b))
	sum := aLong + bLong
	return C.VALUE(ruby.LONG2NUM(sum))
}// ext/GEM_NAME/GEM_NAME.go
/*
#include "example.h"
// TODO: Append this
VALUE rb_example_sum(VALUE self, VALUE a, VALUE b);
*/
import "C"// ext/GEM_NAME/GEM_NAME.go
//export Init_example
func Init_example() {
	rb_mExample := ruby.RbDefineModule("Example")
	// TODO: Append this
	ruby.RbDefineSingletonMethod(rb_mExample, "sum", C.rb_example_sum, 2)
}See also
Run rake ruby:build_example. (bundle exec is not required)
See rake -T for more tasks.
go install golang.org/x/tools/cmd/godoc@latest
godocopen http://localhost:6060/pkg/github.com/ruby-go-gem/go-gem-wrapper/
We provide auto-generated bindings for (almost) all CRuby functions available when including ruby.h 💪
See below for details.