module Steppable
Overview
Implements a#step method for iterating from a value.
Direct including types
Defined in:
steppable.crInstance Method Summary
-
#step(*, to limit = nil, by step, exclusive : Bool = false, &) : Nil
Iterates from
selftolimit incrementing by the amount ofstep on each iteration. -
#step(*, to limit = nil, by step, exclusive : Bool = false)
Iterates from
selftolimit incrementing by the amount ofstep on each iteration.
Instance Method Detail
Iterates fromself tolimit incrementing by the amount ofstep on each
iteration.
Ifexclusive istrue,limit is excluded from the iteration.
ary = [] of Int32
1.step(to: 4, by: 2) do |x|
ary << x
end
ary # => [1, 3]
1.step(to: 4, by: 2).to_a # => [1, 3]
1.step(to: 4, by: 1).to_a # => [1, 2, 3, 4]
1.step(to: 4, by: 1, exclusive: true).to_a # => [1, 2, 3]
The type of each iterated element istypeof(self + step).
Ifto isnil, iteration is open ended.
The starting point (self) is always iterated as first element, with two
exceptions:
- if
selfandto don't compare (i.e.(self <=> to).nil?). Example:1.0.step(Float::NAN) - if the direction ofto differs from the direction of
by. Example:1.step(to: 2, by: -1)
In those cases the iteration is empty.
Iterates fromself tolimit incrementing by the amount ofstep on each
iteration.
Ifexclusive istrue,limit is excluded from the iteration.
ary = [] of Int32
1.step(to: 4, by: 2) do |x|
ary << x
end
ary # => [1, 3]
1.step(to: 4, by: 2).to_a # => [1, 3]
1.step(to: 4, by: 1).to_a # => [1, 2, 3, 4]
1.step(to: 4, by: 1, exclusive: true).to_a # => [1, 2, 3]
The type of each iterated element istypeof(self + step).
Ifto isnil, iteration is open ended.
The starting point (self) is always iterated as first element, with two
exceptions:
- if
selfandto don't compare (i.e.(self <=> to).nil?). Example:1.0.step(Float::NAN) - if the direction ofto differs from the direction of
by. Example:1.step(to: 2, by: -1)
In those cases the iteration is empty.