class

Godot::Dictionary

Inherits Enumerable < Reference < Object

A high-level Crystal wrapper around Godot's native Dictionary type. Provides seamless indexing, Enumerable iteration, and conversion to/from Crystal Hash.

Constructors

from(hash : Hash(K, V)) : Dictionary forall K, V

Creates a Godot::Dictionary from any Crystal Hash

Source
new(initial_hash : Hash(String, String))
Source

Instance methods

[](key : String) : String

Retrieves value by key, or produces KeyError if missing

Source
[]=(key : String, value : String) : String

Sets or updates a key-value pair

Source
[]?(key : String) : String | Nil

Retrieves value by key, or returns nil if missing

Source
clear
Source
delete(key : String) : String | Nil
Source
each

Must yield this collection's elements to the block.

Source
empty?

Returns true if self does not contain any element.

([] of Int32).empty? # => true
([1]).empty?         # => false
[nil, false].empty?  # => false
  • #present? returns the inverse.
Source
has_key?(key : String) : Bool
Source
keys
Source
size

Returns the number of elements in the collection.

[1, 2, 3, 4].size # => 4
Source
to_h

Converts back to a standard Crystal Hash

Source
to_s(io : IO) : Void

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>
Source
values
Source