Skip to content

Symbol#[]: run the full String#[] protocol - #442

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

tannevaled merged 1 commit into
mainfrom
feat/cluster14

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Symbol#[] / #slice only handled an Integer index, an index and
length, a Range or a substring — a Regexp argument raised
no implicit conversion of Regexp into Integer, so none of the Regexp
forms (with or without a capture index, and the $~ they set) worked.

They now delegate to String#[] against the symbol's name, so the whole
protocol — including the Regexp and capture-group forms that set $~ —
works and yields a String (or nil), exactly like sym.to_s[...].
The tiny stringIndex wrapper that only backed the old Symbol#[] is
removed.

Verified against ruby 4.0.6; core/symbol/element_reference_spec
35 → 44 with no regressions and the whole-suite coverage gate stays
at 100.0%. (The remaining errors are the Float / Range-subclass index
coercion that String#[] itself does not yet do — a shared follow-up.)

🤖 Generated with Claude Code

Symbol#[] / #slice only handled an Integer index, an index and length, a
Range or a substring — a Regexp argument raised "no implicit conversion
of Regexp into Integer", so none of the Regexp forms (with or without a
capture index, and the $~ they set) worked.

They now delegate to String#[] against the symbol's name, so the whole
protocol — including the Regexp and capture-group forms that set $~ —
works and yields a String (or nil), exactly like sym.to_s[...]. The
tiny stringIndex wrapper that only backed the old Symbol#[] is removed.

Verified against ruby 4.0.6; core/symbol/element_reference_spec
35 -> 44. (The remaining errors are the Float / Range-subclass index
coercion that String#[] itself does not yet do — a shared follow-up.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 68159ee into main Aug 24, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster14 branch August 24, 2026 16:38
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