Indexable::View(T, U)
Inherits Comparable < Indexable < Enumerable < Iterable < Struct < Value < Object
An IndexableView is a read-only version of any indexable type. This
is useful to give read access to a mutable indexable type such as an
array in a type-safe manner.
The functionality of IndexableView is limited by design, as it just
implements the Indexable mixin requirements by delegating to the
enclosed object.
arr = StaticArray[1, 2, 3, 4]
view = IndexableView(StaticArray(Int32, 4)).new(arr)
view.size # => 4
view[2] # => 3
view.select &.even? # => [2, 4]
view.select! &.even? # does not compile
view.sort # does not compile
Constructors
Instance methods
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Returns the element at the given index, without doing any bounds check.
Indexable makes sure to invoke this method with index in 0...size,
so converting negative indices to positive ones is not needed here.
Clients never invoke this method directly. Instead, they access
elements with #[](index) and #[]?(index).
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.