go-ruby-format is a pure-Go (no cgo) reimplementation of Ruby's format-string engine โ Kernel#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.
Conversion directives ready
Every MRI conversion: integers d/i/u/b/o/x/X, floats f/e/E/g/G/a/A, s string, p inspect, c character, and the %% literal โ each matching reference Ruby’s rounding, padding and sign rules.
Flags, width & precision ready
All flags (- left-justify, + and space sign, 0 zero-pad, # alternate form) with width and precision, including the * form that reads width/precision from an argument.
Named & positional refs ready
Named references %<name>s and %{name} resolved against a hash, and absolute n$ argument indexing โ matching MRI’s mixing rules and its errors for clashing styles.
Bignum & hex-float ready
Arbitrary-precision integer output (%d on a Bignum), and IEEE hex-float (%a / %A) emitted exactly as MRI’s sprintf.c does, down to the mantissa digits and exponent.
Error taxonomy ready
MRI’s full set of ArgumentError / KeyError / TypeError cases โ too few arguments, unknown directive, mixed numbered/unnumbered, missing named key โ surfaced as Go errors.
Differential oracle & coverage ready
A wide format-string corpus rendered both here and by the system ruby, compared byte-for-byte against MRI; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.
- ready capability complete (exit criteria met, nothing material left)
- active in progress (substantial work shipped, not yet finished)
- planned not started yet (or downstream by design)
A faithful port of MRI's sprintf.c in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. It implements every conversion and flag, width/precision with the * argument, named references (%<name>s / %{name}), n$ indexing, Bignum and hex-float. Validated differentially against the system ruby binary โ rendered output compared byte-for-byte. It is a standalone, reusable module extracted from rbgo's internals, and the format backend for the sibling org github.com/go-embedded-ruby.