Skip to content

Range

struct Amethyst::Runtime::Range
implements Enumerable[Int]
end

An integer range. A range literal 1..10 includes its end, and 1...10 leaves it out. Range is a value type, and iterating over it yields each integer from start up to last.

(1..3).each { |i| puts i } # 1, 2, 3
puts (1...10).count # 9
puts (1..10).includes?(10) # True

A range literal with ^ (from the end) is a .NET System.Range instead, which slices arrays and strings.

Signature Description
Range.new(start: Int, end: Int, exclusive: Bool) Creates a range.
start: Int The first value.
end: Int The last value, or one past it when the range is exclusive.
exclusive?: Bool true for a...b.
last: Int The last value the range includes.
count: Int The number of values in the range.
includes?(value: Int): Bool Whether value lies within the range.
to_array: Array[Int] The values of the range as an array.
to_system_range: System::Range The equivalent System.Range, for slicing.
to_s: String The range as written in source, e.g. "1..10".

Only integer ranges are implemented. Ranges of other element types are [TBD] in the literals specification.

class Amethyst::Runtime::RuntimeException < Exception

The exception raised by raise "message" when no exception class is given.