Skip to content

Add String#dump - #444

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster16
Aug 24, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster16

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

String#dump was undefined (NoMethodError). It now returns the receiver
wrapped in double quotes with every non-printable byte, quote, backslash, and
interpolation sigil replaced by a backslash escape, so the result is a valid
Ruby literal that reproduces the receiver:

  • named escapes for \a \b \t \n \v \f \r \e, and \" \\;
  • \# only when # is followed by an interpolation sigil ($, @, {);
  • printable ASCII kept verbatim;
  • a single-byte control (0x00–0x1F, 0x7F) escapes as \xHH — unlike
    #inspect, which uses \uXXXX in a UTF-8 string;
  • a UTF-8 multibyte character always escapes to \uXXXX (BMP) or \u{XXXX…}
    (above U+FFFF), never kept verbatim;
  • a non-ASCII-compatible encoding (UTF-16/UTF-32) additionally carries a
    .force_encoding("NAME") suffix.

The core lives in (*object.String).Dump, alongside Inspect, which it closely
mirrors. The result is always a plain, unfrozen String in the receiver's
encoding.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep; core/string/dump_spec 0 → 16 (the one
remaining error is the .force_encoding example, blocked by rbgo's pre-existing
lack of UTF-16 transcoding in String#encode, not by dump).

🤖 Generated with Claude Code

String#dump was undefined (NoMethodError). It now returns the receiver wrapped
in double quotes with every non-printable byte, quote, backslash, and
interpolation sigil replaced by a backslash escape, so the result is a valid
Ruby literal that reproduces the receiver:

  - named escapes for \a \b \t \n \v \f \r \e, and \" \;
  - `\#` only when `#` is followed by an interpolation sigil ($, @, {);
  - printable ASCII kept verbatim;
  - a single-byte control (0x00-0x1F, 0x7F) escapes as \xHH — unlike #inspect,
    which uses \uXXXX in a UTF-8 string;
  - a UTF-8 multibyte character always escapes to \uXXXX (BMP) or \u{XXXX...}
    (above U+FFFF), never kept verbatim;
  - a non-ASCII-compatible encoding (UTF-16/UTF-32) additionally carries a
    .force_encoding("NAME") suffix.

The core lives in (*object.String).Dump, alongside Inspect, which it closely
mirrors. The result is always a plain, unfrozen String in the receiver's
encoding.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/string/dump_spec 0 -> 16 (the one remaining
error is the .force_encoding example, blocked by rbgo's pre-existing lack of
UTF-16 transcoding in String#encode, not by dump).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 6422b88 into main Aug 24, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster16 branch August 24, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant