class Godot::Dictionary

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

Defined in:

libgodot/collections.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from(hash : Hash(K, V)) : Dictionary forall K, V #

Creates a Godot::Dictionary from any Crystal Hash


def self.new(initial_hash : Hash(K, V)) forall K, V #

def self.new #

Instance Method Detail

def [](key : Variant) : Variant #

Retrieves value by key, or produces KeyError if missing


def [](key : String) : Variant #

def []=(key : Variant, value : Variant) : Variant #

Sets or updates a key-value pair


def []=(key : String, value : Variant) : Variant #

def []=(key : String, value : String) : String #

def []=(key : Variant, value : String) : String #

def []?(key : Variant) : Variant | Nil #

Retrieves value by key, or returns nil if missing


def []?(key : String) : Variant | Nil #

def clear : Void #

def delete(key : Variant) : Variant | Nil #

def delete(key : String) : Variant | Nil #

def each(&block : Tuple(Variant, Variant) -> Void) : Void #
Description copied from module Enumerable({Godot::Variant, Godot::Variant})

Must yield this collection's elements to the block.


def empty? : Bool #
Description copied from module Enumerable({Godot::Variant, Godot::Variant})

Returns true if self does not contain any element.

([] of Int32).empty? # => true
([1]).empty?         # => false
[nil, false].empty?  # => false
  • #present? returns the inverse.

def erase(key : Variant) : Void #

def erase(key : String) : Void #

def has(key : Variant) : Bool #

def has(key : String) : Bool #

def has_key?(key : Variant) : Bool #

def has_key?(key : String) : Bool #

def is_empty : Bool #

def keys : Array(Variant) #

def size : Int64 #
Description copied from module Enumerable({Godot::Variant, Godot::Variant})

Returns the number of elements in the collection.

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

def to_h : Hash(String, String) #

Converts back to a standard Crystal Hash


def to_s(io : IO) : Void #
Description copied from class Reference

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>

def values : Array(Variant) #