Skip to content
@go-ruby-format

go-ruby-format

go-ruby-format

go-ruby-format

Ruby's Kernel#sprintf / format / String#% in pure Go — MRI-compatible, no cgo.

🌐 Website · 📚 Documentation

Docs License: BSD-3-Clause Go 1.26.4+ Coverage 100%


go-ruby-format is a pure-Go (no cgo) reimplementation of Ruby's format-string engineKernel#sprintf, Kernel#format and String#%. It parses an MRI format string and renders it against its arguments, matching reference Ruby byte-for-byte: every conversion (d i f e g s p x o b c %), every flag (- + space 0 #), width and precision including the * argument form, named references (%<name>s and %{name}), absolute n$ argument indexing, arbitrary-precision Bignum and hex-float (%a) output. It was extracted from rbgo's prelude/internals into a reusable standalone library: no dependency on the Ruby runtime, the dependency runs the other way. It is the format-string backend for go-embedded-ruby, bound by rbgo as a native module just like go-ruby-regexp and go-ruby-erb — differential-tested against MRI, 100% coverage, CI green across 6 arches and 3 OSes.

Repositories

Repo What it is
format the library: Ruby's format-string engine in pure Go
docs MkDocs Material documentation, versioned with mike, served at /docs/
go-ruby-format.github.io the Hugo landing page
brand logos and brand assets

Principles

  • Pure Go, zero cgo. Cross-compiles and embeds anywhere; a static binary by default.
  • Extracted from rbgo, reusable by anyone. A standalone library lifted from rbgo's prelude/internals; rbgo binds it as a native module, the same pattern as go-ruby-regexp and go-ruby-erb.
  • MRI byte-exact. Output matches reference Ruby exactly, validated by a differential oracle against the ruby binary.
  • Standalone & reusable. No dependency on the Ruby runtime; the dependency runs the other way.
  • 100% test coverage is the target, enforced as a CI gate.

Status

Complete — MRI byte-exact. Faithful port of MRI's sprintf.c: all conversions (d i f e g s p x o b c %), all flags (- + space 0 #), width and precision including the * argument form, named references (%<name>s / %{name}), n$ indexing, Bignum and hex-float (%a). Validated by a differential oracle against the system ruby — rendered output compared byte-for-byte — at 100% coverage, gofmt + go vet clean, CI green across the six 64-bit Go targets and three OSes. Differential-tested against MRI at 100% coverage, gofmt + go vet clean, CI green across the six 64-bit Go targets (amd64, arm64, riscv64, loong64, ppc64le, s390x) and three operating systems. It is bound into the go-embedded-ruby (rbgo) ecosystem as a native module.

BSD-3-Clause.

Popular repositories Loading

  1. brand brand Public

    Brand assets — logos & icons

  2. .github .github Public

  3. go-ruby-format.github.io go-ruby-format.github.io Public

    HTML

  4. docs docs Public

  5. format format Public

    Go

Repositories

Showing 5 of 5 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…