A range is an interval of consecutive integers represented by its endpoints. A range is created with ..
operator for inclusive range and ...
operator for exclusive range.
Methods
contains(value)
Return true
if the range contains value
.
IO.println((42..69).contains(55)) #> true
IO.println((42..69).contains(12)) #> false
from
Return the first endpoint of the range.
IO.println((42..69).from) #> 42
IO.println((12..7).from) #> 12
See also: to
inclusive
Return true
is the range includes to
(from
is always included).
IO.println((42..69).inclusive) #> true
IO.println((42...69).inclusive) #> false
iterate(iterator), iterator_value(iterator)
Implement the iterator protocol to iterate over the range.
max
Return the maximum endpoint of the range.
IO.println((42..69).max) #> 69
IO.println((12..7).max) #> 12
See also: min
min
Return the minimum endpoint of the range.
IO.println((42..69).min) #> 42
IO.println((12..7).min) #> 7
See also: max
size
Return the number of elements in the range.
IO.println((42..69).size) #> 28
IO.println((42...69).size) #> 27
to
Return the second endpoint of the range. If the range is inclusive, this value is included, otherwise, it is excluded.
IO.println((42..69).to) #> 69
IO.println((12..7).to) #> 7
See also: from