Skip to content

Numeric#step: support keyword (to:/by:) and mixed arguments - #422

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster3
Aug 21, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster3

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Integer#step and Float#step only accepted positional (limit, step)
arguments, so 1.step(by: 2, to: 10) and the mixed 1.step(10, by: 2)
raised can't iterate from 1 (the keyword Hash was taken as the limit).
core/numeric/step_spec.rb 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; a
missing limit means an unbounded (endless) walk. Both methods now route a
nil limit to numericStepEndless and share the sized Enumerator.

Three edges are aligned with MRI as well:

  • a String step raises ArgumentError (rather than being silently
    parsed as a number) at iteration and from #size;
  • an infinite step yields the start value exactly once instead of
    looping forever;
  • 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.

The 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, the
whole-suite coverage gate stays at 100.0%, and a full language+core sweep
shows no regressions.

🤖 Generated with Claude Code

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>
@tannevaled
tannevaled merged commit aec07f0 into main Aug 21, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster3 branch August 21, 2026 11:56
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