Skip to content

class Athena::ORM::ArrayCollection(T)
inherits Athena::ORM::BaseCollection #

A simple wrapper around Array implementing the AORM::Collection interface.

Collection fields are initialized with an empty one; see AORM::Collection for how the ORM manages them from there.

property groups : AORM::Collection(Group) = AORM::ArrayCollection(Group).new

It has no ties to the ORM, so it's also suitable for building up a collection before assigning it to an entity.

Included modules

Athena::ORM::Collection Indexable

Constructors#

.new(elements : Array(T) = [] of T)#

Creates a collection holding a copy of elements.

View source

.new(elements : Enumerable(T))#

Creates a collection holding the elements of elements.

View source

Methods#

#<<(element : T) : self#

Adds an element to the collection (alias for add).

View source

#[]=(index : Int, value : T) : T#

Sets the element at the given index.

View source

#[]?(index : Int) : T | Nil#

Returns the element at the given index, or nil if out of bounds.

View source

#add(element : T) : Nil#

Adds an element to the collection.

View source

#clear : Nil#

Removes all elements from the collection.

View source

#delete(element : T) : T | Nil#

Removes every occurrence of element from the collection. Returns the removed element, or nil if not found.

View source

#first? : T | ::Nil#

Returns the first element, or nil if empty.

View source

#includes?(element : T) : Bool#

Returns whether the collection contains the element.

View source

#last? : T | ::Nil#

Returns the last element, or nil if empty.

View source

#remove_element(element : T) : Bool#

Removes every occurrence of element, and returns whether it was present.

View source

#size : Int32#

Returns the number of elements in the collection.

View source

#to_a : Array(T)#

Returns a copy of the elements array.

View source

#unsafe_fetch(index : Int) : T#

Returns the element at the given index, without doing any bounds check.

View source