Open-Source Wikis

/

Ruby

/

Fun facts

ruby/ruby

Fun facts

A few oddities, ancient corners, and self-referential moments in the Ruby source.

The genesis date

include/ruby/version.h defines:

#define RUBY_BIRTH_YEAR 1993
#define RUBY_BIRTH_MONTH 2
#define RUBY_BIRTH_DAY 24

Ruby's birthday is 24 February 1993, the day Matz started designing the language. The first public release was almost three years later, in December 1995.

The known bugs file

KNOWNBUGS.rb exists in the repo root. It is a Ruby script of currently-known interpreter bugs that should still be parseable (or hit the issue described in a comment). At the time of this snapshot it is just under 200 bytes — the list is intentionally short.

The longest single source files

The all-time C-file champions are mostly generated:

  • prism/prism.c — ~980 KB, generated by Prism's templater (prism/templates/)
  • parse.c (built artifact) — ~519 KB grammar, hand-written in parse.y
  • compile.c — ~513 KB and the largest hand-edited C file
  • io.c — ~436 KB
  • string.c — ~359 KB

compile.c walks the AST and emits VM bytecode. It has been continuously modified since 2007 and is still the bottleneck for new language feature work.

Two parsers, three syntaxes

The Ruby compiler supports three distinct surface syntaxes through parse.y:

  1. The Ruby language itself.
  2. The Ripper library — ext/ripper/ reuses the same grammar to expose tokens and an alternative AST to user code.
  3. Universal parser — a stripped-down embedding mode (universal_parser.c) used by tools that need to parse Ruby without linking the full VM.

Then there's Prism, which is a wholly separate parser written by hand.

Stdlib written in Ruby (and built into the binary)

A fair fraction of "core" classes have their public methods written in Ruby, not C. Examples:

  • array.rb, hash.rb, string.rb (split with string.c), set.rb, dir.rb, io.rb, numeric.rb, gc.rb, ractor.rb, thread_sync.rb, marshal.rb, pack.rb, kernel.rb, nilclass.rb, pathname_builtin.rb, trace_point.rb, warning.rb, and more.

These files are compiled at build time into the binary by the "builtin" pipeline (tool/mk_builtin_loader.rb, mini_builtin.c, builtin.c). They can call low-level C primitives via the Primitive.* interface and are loaded before user code runs.

Hand-written coroutine assembly

coroutine/<arch>/Context.S switches Fiber stacks. There are implementations for x86, x86_64, arm32, arm64, ppc64le, riscv64, s390x, loongarch64, mips64, sparc64, win32, win64, copy (a slow generic fallback), and ucontext. The directory has more architectures than most projects ever target.

The Lrama coup

tool/lrama/ contains an entire LALR(1) parser generator, written in Ruby, that replaces GNU Bison. As of Ruby 3.3 the only Bison-like tool needed to build CRuby is itself a Ruby gem. The grammar in parse.y therefore has to be parseable by Bison-compatible Lrama at all times.

The "rdoc-ref" pattern

README.md and a handful of other docs reference each other with rdoc-ref: URIs (e.g., [日本語](rdoc-ref:README.ja.md)). These resolve in the rendered documentation site but show up as raw text on GitHub. They are an artifact of how rdoc cross-links files within a project.

The mailmap

.mailmap is over 20 KB and maps thousands of historical author/email aliases. Many contributors shifted between work and personal email addresses across decades; the mailmap normalises blame and git log output. It is rebuilt by tool/gen-mailmap.rb.

Two "weakmap" types

weakmap.c exposes two distinct classes: ObjectSpace::WeakMap (weak keys and values) and ObjectSpace::WeakKeyMap (only the keys are weak). The latter was added because the former's "garbage-collect either side" semantics turn out to be surprising in practice — entries can disappear because their value got collected.

The frozen $<

re.c, in Ruby 4.x, makes all Regexp instances frozen — not just literals. (This change is recorded in NEWS.md.) Subclasses of Regexp are still mutable for backward compatibility.

Rust at the Ruby core

The top-level Cargo.toml is a workspace with three members: yjit, zjit, and a tiny jit crate. The package itself is name = "ruby", version = "0.0.0", with a comment that says "Don't publish to crates.io". So technically there is a Rust crate called "ruby" that builds into the Ruby binary, but it lives only here.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Fun facts – Ruby wiki | Factory