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({String, String})
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(String, String))
- .new
Instance Method Summary
-
#[](key : String) : String
Retrieves value by key, or produces KeyError if missing
-
#[]=(key : String, value : String) : String
Sets or updates a key-value pair
-
#[]?(key : String) : String | Nil
Retrieves value by key, or returns nil if missing
- #clear : Void
- #delete(key : String) : String | Nil
-
#each(&block : Tuple(String, String) -> Void) : Void
Must yield this collection's elements to the block.
-
#empty? : Bool
Returns
trueifselfdoes not contain any element. - #has_key?(key : String) : Bool
- #keys : Array(String)
-
#size : Int32
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(String)
Constructor Detail
Creates a Godot::Dictionary from any Crystal Hash
Instance Method Detail
Retrieves value by key, or returns nil if missing
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>