Repository navigation
Symbol#[]: run the full String#[] protocol - #442
Merged
Merged
Conversation
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>
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.
Symbol#[]/#sliceonly handled an Integer index, an index andlength, a Range or a substring — a
Regexpargument raisedno implicit conversion of Regexp into Integer, so none of the Regexpforms (with or without a capture index, and the
$~they set) worked.They now delegate to
String#[]against the symbol's name, so the wholeprotocol — including the Regexp and capture-group forms that set
$~—works and yields a
String(ornil), exactly likesym.to_s[...].The tiny
stringIndexwrapper that only backed the oldSymbol#[]isremoved.
Verified against ruby 4.0.6;
core/symbol/element_reference_spec35 → 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