go-ruby-yaml

Ruby's Psych YAML emitter & loader in pure Go โ€” MRI-compatible, no cgo.

pure Go ยท zero cgo Psych-compatible Dump / Load / SafeLoad anchors & aliases !ruby/object: Symbol ยท Time ยท Range bignum block + flow styles MRI byte-exact 100% coverage 6 arches
Documentation GitHub
Documentation (MkDocs Material + mike) License: BSD-3-Clause Go 1.26.4+ Coverage 100%

go-ruby-yaml is a pure-Go (no cgo) reimplementation of Ruby's Psych YAML library โ€” a Dump emitter and a Load / SafeLoad loader that match reference Ruby's serialization byte-for-byte. It round-trips Ruby values through YAML the way Psych does: anchors and aliases for shared and cyclic structure, the !ruby/object: and related Ruby tags, Symbol / Time / Range / bignum scalars, and both block and flow styles. 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 YAML 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.

Scanner & parser ready

A YAML 1.1 scanner and parser following Psych’s event model โ€” documents, mappings, sequences, scalars in plain / single / double / literal / folded styles, and the directive and document markers.

Dump emitter ready

Dump(v) emits Psych-compatible YAML: block style by default with flow where Psych uses it, correct scalar quoting, and stable key ordering โ€” matching reference Ruby’s output byte-for-byte.

Load & SafeLoad ready

Load(s) builds the full Ruby value graph; SafeLoad restricts to the safe scalar/collection subset, refusing arbitrary !ruby/object: instantiation exactly as Psych’s safe loader does.

Anchors, aliases & Ruby tags ready

Anchors &a and aliases *a for shared and cyclic structure, plus the !ruby/object:, !ruby/symbol, !ruby/range and related tags round-tripped the way Psych writes and reads them.

Ruby scalar types ready

Symbol, Time, Range and arbitrary-precision bignum scalars emitted and parsed with Psych’s tag and formatting conventions.

Differential oracle & coverage ready

A wide value corpus dumped and loaded both here and by the system ruby/Psych, compared byte-for-byte; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.

A faithful port of Ruby's Psych emitter and loader in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. It emits and parses anchors and aliases, the !ruby/object: Ruby tags, Symbol / Time / Range / bignum scalars, and block and flow styles. Validated differentially against the system ruby binary โ€” emitted YAML and loaded values compared against Psych. It is a standalone, reusable module extracted from rbgo's internals, and the YAML backend for the sibling org github.com/go-embedded-ruby.