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


[View source]
def self.new(initial_hash : Hash(String, String)) #

[View source]
def self.new #

[View source]

Instance Method Detail

def [](key : String) : String #

Retrieves value by key, or produces KeyError if missing


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

Sets or updates a key-value pair


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

Retrieves value by key, or returns nil if missing


[View source]
def clear : Void #

[View source]
def delete(key : String) : String | Nil #

[View source]
def each(&block : Tuple(String, String) -> Void) : Void #
Description copied from module Enumerable({String, String})

Must yield this collection's elements to the block.


[View source]
def empty? : Bool #
Description copied from module Enumerable({String, String})

Returns true if self does not contain any element.

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

[View source]
def has_key?(key : String) : Bool #

[View source]
def keys : Array(String) #

[View source]
def size : Int32 #
Description copied from module Enumerable({String, String})

Returns the number of elements in the collection.

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

[View source]
def to_h : Hash(String, String) #

Converts back to a standard Crystal Hash


[View source]
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>

[View source]
def values : Array(String) #

[View source]