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.crlibgodot/variant.cr
Constructors
-
.from(hash : Hash(K, V)) : Dictionary forall K, V
Creates a Godot::Dictionary from any Crystal Hash
- .from_bridge_payload(payload_ptr : Pointer(Void)) : Dictionary
- .new(initial_hash : Hash(K, V)) forall K, V
- .new
- .new(**kwargs)
Instance Method Summary
-
#[](key : Variant) : Variant
Retrieves value by key, or produces KeyError if missing
- #[](key : String) : Variant
- #[](key : Symbol) : Variant
-
#[]=(key : Variant, value : Variant) : Variant
Sets or updates a key-value pair
- #[]=(key : String, value : Variant) : Variant
- #[]=(key : Symbol, value : Variant) : Variant
- #[]=(key : String | Symbol | Variant, value)
-
#[]?(key : Variant) : Variant | Nil
Retrieves value by key, or returns nil if missing
- #[]?(key : String) : Variant | Nil
- #[]?(key : Symbol) : Variant | Nil
- #clear : Void
- #clone : Dictionary
- #delete(key : Variant) : Variant | Nil
- #delete(key : String) : Variant | Nil
- #delete(key : Symbol) : Variant | Nil
-
#dig?(first : String | Symbol | Variant, *rest, as type : T.class) : {Godot::Variant, Godot::Variant} | Nil forall T
Digs through nested Dictionaries by keys, returning typed value or nil
-
#dup : Dictionary
Returns a shallow copy of this object.
- #duplicate(deep : Bool = false) : Dictionary
-
#each(& : Tuple(Variant, Variant) -> ) : 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
- #erase(key : Symbol) : Void
-
#get(key : String | Symbol | Variant, as type : T.class, default : {Godot::Variant, Godot::Variant}) : {Godot::Variant, Godot::Variant} forall T
Generic typed getter with default value
-
#get?(key : String | Symbol | Variant, as type : T.class) : {Godot::Variant, Godot::Variant} | Nil forall T
Generic safe typed getter returning nil on missing or type mismatch
- #has(key : Variant) : Bool
- #has(key : String) : Bool
- #has(key : Symbol) : Bool
- #has_key?(key : Variant) : Bool
- #has_key?(key : String) : Bool
- #has_key?(key : Symbol) : 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)
- #write_bridge_payload(ret_ptr : Pointer(Void)) : Void
Instance methods inherited from class Object
try?(&)try? try?
Constructor Detail
Creates a Godot::Dictionary from any Crystal Hash
Instance Method Detail
Digs through nested Dictionaries by keys, returning typed value or nil
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.
Generic typed getter with default value
Generic safe typed getter returning nil on missing or type mismatch
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>