| Class | Interval |
| In: |
lib/facet/interval.rb
|
| Parent: | Object |
require ‘facet/infinity‘
| VERSION | = | '0.9.0' |
Unary shorthands. These return a new interval exclusive of first, last or both sentinels, repectively.
Returns the direction of the interval indicated by +1, 0 or -1.
(1..5).direction #=> 1 (5..1).direction #=> -1 (1..1).direction #=> 0
Iterates over the interval, passing each _n_th element to the block. If n is not given then n defaults to 1. Each _n_th step is determined by invoking +++ or +\-+ n, depending on the direction of the interval. If n is negative the iteration is preformed in reverse form end sentinal to front sentinal. A second parameter, d, can be given in which case the applied step is calculated as a fraction of the interval’s length times n / d. This allows iteration over the whole interval in equal sized segments.
1..5.each { |e| ... } #=> 1 2 3 4 5
1..5.each(2) { |e| ... } #=> 1 3 5
1..5.each(1,2) { |e| ... } #=> 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
Returns a new interval with either the first or the last sentinel exclusive. If the parameter is false, the deafult, then the first sentinel is excluded; if the parameter is true, the last sentinel is excluded.