Repository navigation
Add String#dump - #444
Merged
Merged
Add String#dump#444
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
String#dumpwas undefined (NoMethodError). It now returns the receiverwrapped 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:
\a \b \t \n \v \f \r \e, and\"\\;\#only when#is followed by an interpolation sigil ($,@,{);0x00–0x1F,0x7F) escapes as\xHH— unlike#inspect, which uses\uXXXXin a UTF-8 string;\uXXXX(BMP) or\u{XXXX…}(above U+FFFF), never kept verbatim;
.force_encoding("NAME")suffix.The core lives in
(*object.String).Dump, alongsideInspect, which it closelymirrors. The result is always a plain, unfrozen
Stringin the receiver'sencoding.
Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep;
core/string/dump_spec0 → 16 (the oneremaining error is the
.force_encodingexample, blocked by rbgo's pre-existinglack of UTF-16 transcoding in
String#encode, not bydump).🤖 Generated with Claude Code