module Array::Wrapper(T)
Overview
Wraps an Array
object. The including type will behave as a read-only
array, where objects returned by methods will be wrapped as well if
the return type is the same as the original array.
class CustomArray(T)
include ArrayWrapper(T)
end
arr = CustomArray.new([1, 2, 3, 4])
arr.size # => 4
arr[0]? # => 1
arr[6]? # => nil
arr.select(&.even?) # => [2, 4]
arr.select(&.even?).class # => CustomArray(Int32)
arr.select!(&.even?) # does not compile
Included Modules
- Comparable(Indexable(T))
- Indexable(T)
- Wrapper(Array(T))
Direct including types
Defined in:
views/array_wrapper.crConstructors
Instance Method Summary
- #&(*args, **options)
- #&(*args, **options, &)
- #*(*args, **options)
- #*(*args, **options, &)
- #+(*args, **options)
- #+(*args, **options, &)
- #-(*args, **options)
- #-(*args, **options, &)
- #<=>(rhs : self) : Int32
- #<=>(*args, **options)
- #<=>(*args, **options, &)
- #[](*args, **options)
- #[](*args, **options, &)
- #[]?(*args, **options)
- #[]?(*args, **options, &)
- #|(*args, **options)
- #|(*args, **options, &)
- #compact(*args, **options)
- #compact(*args, **options, &)
- #each_repeated_permutation(*args, **options)
- #each_repeated_permutation(*args, **options, &)
-
#each_slice(n : Int, reuse : Array(T) | Bool = false, & : self -> ) : Nil
Invokes
Array#[]each_slice(n, reuse)
on the enclosed array, yielding a wrapped array each time. - #first(*args, **options)
- #first(*args, **options, &)
- #flatten(*args, **options)
- #flatten(*args, **options, &)
-
#group_by(& : T -> U) : Hash(U, self) forall U
Returns the result of calling
Array#group_by(&)
on the enclosed array with the hash's values wrapped. - #index(*args, **options)
- #index(*args, **options, &)
- #inspect(io : IO) : Nil
- #last(*args, **options)
- #last(*args, **options, &)
- #map(*args, **options)
- #map(*args, **options, &)
- #map_with_index(*args, **options)
- #map_with_index(*args, **options, &)
-
#partition(& : T -> _) : Tuple(self, self)
Returns the wrapped result of calling
Array#partition(&)
on the enclosed array. - #reject(*args, **options)
- #reject(*args, **options, &)
- #remaining_capacity(*args, **options)
- #remaining_capacity(*args, **options, &)
- #repeated_permutations(*args, **options)
- #repeated_permutations(*args, **options, &)
- #reverse(*args, **options)
- #reverse(*args, **options, &)
- #rotate(*args, **options)
- #rotate(*args, **options, &)
- #sample(*args, **options)
- #sample(*args, **options, &)
- #select(*args, **options)
- #select(*args, **options, &)
- #shuffle(*args, **options)
- #shuffle(*args, **options, &)
- #size(*args, **options)
- #size(*args, **options, &)
- #skip(*args, **options)
- #skip(*args, **options, &)
- #skip_while(*args, **options)
- #skip_while(*args, **options, &)
- #sort(*args, **options)
- #sort(*args, **options, &)
- #sort_by(*args, **options)
- #sort_by(*args, **options, &)
- #take_while(*args, **options)
- #take_while(*args, **options, &)
-
#to_a : Array(T)
Returns the wrapped array.
- #to_s(*args, **options)
- #to_s(*args, **options, &)
- #transpose(*args, **options)
- #transpose(*args, **options, &)
- #uniq(*args, **options)
- #uniq(*args, **options, &)
- #unsafe_fetch(*args, **options)
- #unsafe_fetch(*args, **options, &)
- #unstable_sort(*args, **options)
- #unstable_sort(*args, **options, &)
- #unstable_sort_by(*args, **options)
- #unstable_sort_by(*args, **options, &)
Instance methods inherited from module Wrapper(Array(T))
==(rhs : T(T)) : Bool==(rhs : self) : Bool ==, pretty_print(*args, **options)
pretty_print(*args, **options, &) pretty_print, to_s(*args, **options)
to_s(*args, **options, &) to_s, wrapped : T(T) wrapped
Constructor methods inherited from module Wrapper(Array(T))
new(wrapped : T(T) = T.new)
new
Instance methods inherited from module Indexable(T)
[](index : Int, other : Int, *indexes : Int) : self[](indexes : Tuple) : Tuple
[](indexes : Indexable(Int)) : self
[](indexes : Enumerable(Int)) : self [], view : View(self, T) view
Constructor Detail
Instance Method Detail
Invokes Array#[]each_slice(n, reuse)
on the enclosed array,
yielding a wrapped array each time.
Returns the result of calling Array#group_by(&)
on the enclosed
array with the hash's values wrapped.
Returns the wrapped result of calling Array#partition(&)
on the
enclosed array.