Skip to content

Add String#hex - #447

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster19
Aug 25, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster19

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

String#hex was undefined (NoMethodError). It reads the string as a base-16
integer: an optional leading sign, an optional 0x/0X prefix (b/d/o are
hex digits, so no other radix prefix is special), hex digits with a single
underscore allowed between them, stopping at the first non-hex character and
returning 0 when no digit is present; a value beyond a machine word yields a
Bignum.

The digit scan, underscore rule, and Bignum conversion are factored out of
strOct into a shared accumInum (with inumSignSkip for the leading sign), so
String#oct and String#hex share one implementation rather than a copy.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep; core/string/hex_spec 0 → 7,
core/string/oct_spec unchanged at 17.

🤖 Generated with Claude Code

String#hex was undefined (NoMethodError). It reads the string as a base-16
integer: an optional leading sign, an optional "0x"/"0X" prefix (b/d/o are hex
digits, so no other radix prefix is special), hex digits with a single
underscore allowed between them, stopping at the first non-hex character and
returning 0 when no digit is present; a value beyond a machine word yields a
Bignum.

The digit scan, underscore rule, and Bignum conversion are factored out of
strOct into a shared accumInum (with inumSignSkip for the leading sign), so
String#oct and String#hex share one implementation rather than a copy.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/string/hex_spec 0 -> 7, core/string/oct_spec
unchanged at 17.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 404b56c into main Aug 25, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster19 branch August 25, 2026 09:29
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