Skip to content

Refine signature of Numeric#step and add type of Enumerator::ArithmeticSequence#2600

Merged
ksss merged 1 commit intoruby:masterfrom
ksss:numeric-step
Aug 10, 2025
Merged

Refine signature of Numeric#step and add type of Enumerator::ArithmeticSequence#2600
ksss merged 1 commit intoruby:masterfrom
ksss:numeric-step

Conversation

@ksss
Copy link
Collaborator

@ksss ksss commented Jul 15, 2025

There are several mistakes in the type of the #step method.

Problem

Mistakes in block variable type

The one of Integer#step overload is here.

(Numeric limit, ?Integer step) { (Integer) -> void } -> void

But, i is Float in following code.

1.step(3.0, 1) { |i| p i }
# 1.0
# 2.0
# 3.0

Return type without block

In ruby, the method that returns Enumerator::ArithmeticSequence but signature returns Enumerator type.

1.step #=> Enumerator::ArithmeticSequence

Documentation

When hovering over 1.step in Steep, I cannot read the rdoc in LSP.

Solution

Add type of Enumerator::ArithmeticSequence

Return Enumerator::ArithmeticSequence to match the actual behavior.
Enumerator::ArithmeticSequence introduced from ruby v2.6.
We will be able to type Enumerator::ArithmeticSequence specific methods.

1.step.begin #=> Numeric

Notes

The Enumerator::ArithmeticSequence holds several values.

a = 1.step(3r, 1.0)
a.begin #=> 1
a.step #=> 1.0
a.end #=> 3r

However, the Ruby specification is more complex than expected.

1.step.end #=> nil
(..3).step(1).begin #=> nil
1.step(3.0, 1r) { p it } #=> 1.0, 2.0, 3.0

The use of Enumerator::ArithmeticSequence is limited, and since there haven't been any requests for it so far, I don't think there's a need to make it overly complex.

Unify signatures to Numeric#step

It is possible to copy the documentation, but if the goal is to keep it simple, unifying it under Numeric#step would make it easier to manage.

@ksss ksss added this to the RBS 4.0 milestone Jul 15, 2025
And add type of `Enumerator::ArithmeticSequence`.
@ksss ksss added this pull request to the merge queue Aug 10, 2025
Merged via the queue into ruby:master with commit de08397 Aug 10, 2025
20 checks passed
@ksss ksss deleted the numeric-step branch August 10, 2025 07:58
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