Class: Godot::Dictionary

Inherits:
Variant show all
Defined in:
lib/godot_rb/enumerable.rb

Constant Summary collapse

VARIANT_TYPE =
27

Constants included from Godot

VERSION

Class Method Summary collapse

Methods inherited from Variant

#get, #key?, #method_missing, #respond_to_missing?, #set, #to_godot

Methods included from Godot

init_level

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Godot::Variant

Class Method Details

.[](**elems) ⇒ Object



19
# File 'lib/godot_rb/enumerable.rb', line 19

def self.[](**elems) = from(elems)

.from(enum) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/godot_rb/enumerable.rb', line 6

def self.from(enum)
  dictionary = new
  enum.each_with_index do|pair, index|
    if pair.size != 2
      raise ArgumentError, "wrong array length at #{index} (expected 2, was #{pair.size})"
    end
    # https://github.com/soutaro/steep/issues/947
    # dictionary.[]=(*pair)
    key, value = pair
    dictionary[key] = value
  end
  dictionary
end