class
Godot::Dictionary
- Godot::Dictionary
- Reference
- Object
Overview
A high-level Crystal wrapper around Godot's native Dictionary type. Provides seamless indexing, Enumerable iteration, and conversion to/from Crystal Hash.
Included Modules
- Enumerable({Godot::Variant, Godot::Variant})
Defined in:
libgodot/collections.crConstructors
-
.from(hash : Hash(K, V)) : Dictionary forall K, V
Creates a Godot::Dictionary from any Crystal Hash
- .new(initial_hash : Hash(K, V)) forall K, V
- .new
Instance Method Summary
-
#[](key : Variant) : Variant
Retrieves value by key, or produces KeyError if missing
- #[](key : String) : Variant
-
#[]=(key : Variant, value : Variant) : Variant
Sets or updates a key-value pair
- #[]=(key : String, value : Variant) : Variant
- #[]=(key : String, value : String) : String
- #[]=(key : Variant, value : String) : String
-
#[]?(key : Variant) : Variant | Nil
Retrieves value by key, or returns nil if missing
- #[]?(key : String) : Variant | Nil
- #clear : Void
- #delete(key : Variant) : Variant | Nil
- #delete(key : String) : Variant | Nil
-
#each(&block : Tuple(Variant, Variant) -> Void) : Void
Must yield this collection's elements to the block.
-
#empty? : Bool
Returns
trueifselfdoes not contain any element. - #erase(key : Variant) : Void
- #erase(key : String) : Void
- #has(key : Variant) : Bool
- #has(key : String) : Bool
- #has_key?(key : Variant) : Bool
- #has_key?(key : String) : Bool
- #is_empty : Bool
- #keys : Array(Variant)
-
#size : Int64
Returns the number of elements in the collection.
-
#to_h : Hash(String, String)
Converts back to a standard Crystal Hash
-
#to_s(io : IO) : Void
Appends a short String representation of this object which includes its class name and its object address.
- #values : Array(Variant)
Constructor Detail
Creates a Godot::Dictionary from any Crystal Hash
Instance Method Detail
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 number of elements in the collection.
[1, 2, 3, 4].size # => 4
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>