class
Godot::GodotArray(T)
- Godot::GodotArray(T)
- Reference
- Object
Overview
A high-level Crystal wrapper around Godot's native Array type.
Named GodotArray to avoid shadowing Crystal's top-level ::Array.
Implements Enumerable and provides seamless conversion to/from Crystal Array.
Included Modules
- Enumerable(T)
Defined in:
libgodot/collections.crConstructors
Class Method Summary
- .from(items : Array(T)) : GodotArray(T)
- .from_bridge_payload(payload_ptr : Pointer(Void)) : GodotArray(T)
Instance Method Summary
- #<<(value : T) : self
- #[](index : Int32) : T
- #[](index : Int64) : T
- #[]=(index : Int32, value : T) : T
- #[]=(index : Int64, value : T) : T
- #[]?(index : Int32) : T | Nil
- #[]?(index : Int64) : T | Nil
- #append(value : T) : self
- #clear : Void
- #clone : GodotArray(T)
-
#dup : GodotArray(T)
Returns a shallow copy of this object.
- #duplicate(deep : Bool = false) : GodotArray(T)
-
#each(& : T -> ) : Void
Must yield this collection's elements to the block.
-
#empty? : Bool
Returns
trueifselfdoes not contain any element. - #filter_as(type : U.class) : Array(U) forall U
-
#first? : T | Nil
Returns the first element in the collection.
- #is_empty : Bool
- #last? : T | Nil
- #pop : T | Nil
- #push(value : T) : self
-
#sample : T | Nil
Returns a random element from
self. - #shift : T | Nil
-
#size : Int64
Returns the number of elements in the collection.
-
#to_a : Array(T)
Returns an
Arraywith all the elements in the collection. - #to_array : Array(T)
-
#to_s(io : IO) : Void
Appends a short String representation of this object which includes its class name and its object address.
- #write_bridge_payload(ret_ptr : Pointer(Void)) : Void
Instance methods inherited from class Object
try?(&)try? try?
Constructor Detail
Class Method Detail
Instance Method Detail
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self into it.
Must yield this collection's elements to the block.
Returns true if self does not contain any element.
([] of Int32).empty? # => true
([1]).empty? # => false
[nil, false].empty? # => false
#present?returns the inverse.
Returns the first element in the collection.
When the collection is empty, returns nil.
([1, 2, 3]).first? # => 1
([] of Int32).first? # => nil
Returns a random element from self. All elements have equal probability of
being drawn.
Raises IndexError if self is empty.
a = [1, 2, 3]
a.sample # => 2
a.sample # => 1
Uses the random instance when provided if the randomness needs to be controlled or to follow some traits. For example the following calls use a custom seed or a secure random source:
a.sample(Random.new(1)) # => 3
a.sample(Random::Secure) # => 1
Returns the number of elements in the collection.
[1, 2, 3, 4].size # => 4
Returns an Array with all the elements in the collection.
(1..5).to_a # => [1, 2, 3, 4, 5]
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>