1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

enumerator.c: Introduce Enumerator::ArithmeticSequence

This commit introduces new core class Enumerator::ArithmeticSequence.
Enumerator::ArithmeticSequence is a subclass of Enumerator, and
represents a number generator of an arithmetic sequence.

After this commit, Numeric#step and Range#step without blocks
returned an ArithmeticSequence object instead of an Enumerator.

This class introduces the following incompatibilities:

- You can create a zero-step ArithmeticSequence,
  and its size is not ArgumentError, but Infinity.
- You can create a negative-step ArithmeticSequence from a range.

[ruby-core:82816] [Feature #13904]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2018-08-06 09:08:28 +00:00
parent 1777e39c2a
commit f15069338d
11 changed files with 883 additions and 47 deletions

View file

@ -259,15 +259,15 @@ describe :numeric_step, :shared => true do
describe "when no block is given" do
it "returns an Enumerator when step is 0" do
1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator)
1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator::ArithmeticSequence)
end
it "returns an Enumerator when not passed a block and self > stop" do
1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator)
1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator::ArithmeticSequence)
end
it "returns an Enumerator when not passed a block and self < stop" do
1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator)
1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator::ArithmeticSequence)
end
it "returns an Enumerator that uses the given step" do