Repository navigation
Numeric#step: support keyword (to:/by:) and mixed arguments - #422
Merged
Merged
Conversation
Integer#step and Float#step only accepted positional (limit, step) arguments, so the keyword form 1.step(by: 2, to: 10) and the mixed form 1.step(10, by: 2) raised "can't iterate from 1" (the keyword Hash was taken as the limit). numeric/step_spec went 104 -> 119. A shared stepBounds helper resolves (limit, step) from the positional and to:/by: keyword arguments, applying MRI's rules: a limit or step may be given positionally or by keyword but not both, an unknown keyword or more than two positional arguments is an ArgumentError, and a missing limit means an unbounded (endless) walk. Both step methods now route a nil limit to numericStepEndless and share the sized-Enumerator size. Also aligned three edges with MRI: a String step raises ArgumentError (not a silent numeric parse) at iteration and from #size (rejectStringStep in numericStep/numericStepEndless/stepSize); an infinite step yields the start value exactly once instead of looping; and stepSize reports an unbounded (nil-limit) sequence as infinite and the both-infinite / infinite-step cases the way MRI counts them (1 or 0). A bare step with no limit is now the unbounded walk MRI performs, not an ArgumentError; two tests that had encoded the old behaviour are updated. Remaining step_spec failures are Enumerator::ArithmeticSequence (a separate unimplemented class) and a pre-existing VM limitation where a block passed to a lambda is not delivered to its body, which the shared example harness relies on. Verified against ruby 4.0.6; numeric/step_spec 104 -> 119, whole-suite coverage gate stays at 100.0%, full language+core sweep shows no regressions. 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.
Integer#stepandFloat#steponly accepted positional(limit, step)arguments, so
1.step(by: 2, to: 10)and the mixed1.step(10, by: 2)raised
can't iterate from 1(the keyword Hash was taken as the limit).core/numeric/step_spec.rbwent 104 → 119.A shared
stepBoundshelper resolves(limit, step)from the positionaland
to:/by:keyword arguments, applying MRI's rules: a limit or stepmay be given positionally or by keyword but not both; an unknown
keyword, or more than two positional arguments, is an
ArgumentError; amissing limit means an unbounded (endless) walk. Both methods now route a
nil limit to
numericStepEndlessand share the sized Enumerator.Three edges are aligned with MRI as well:
ArgumentError(rather than being silentlyparsed as a number) at iteration and from
#size;looping forever;
stepSizereports an unbounded (nil-limit) sequence as infinite, andthe both-infinite / infinite-step cases the way MRI counts them (1 or
0).
A bare
stepwith no limit is now the unbounded walk MRI performs, notan
ArgumentError; two tests that had encoded the old behaviour areupdated.
The remaining
step_specfailures areEnumerator::ArithmeticSequence(a separate unimplemented class) and a pre-existing VM limitation where a
block passed to a lambda is not delivered to its body — which the shared
example harness relies on.
Verified against ruby 4.0.6;
numeric/step_spec104 → 119, thewhole-suite coverage gate stays at 100.0%, and a full language+core sweep
shows no regressions.
🤖 Generated with Claude Code