Class: Godot::Variant::AbstractArray

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

Direct Known Subclasses

Array

Constant Summary

Constants inherited from Godot::Variant

VARIANT_TYPE

Constants included from Godot

Godot::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Godot::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



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

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

.from(enum) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/godot_rb/enumerable.rb', line 26

def self.from(enum)
  array = new
  size = enum.lazy.size
  if size
    array.resize(size)
    enum.each_with_index {|elem, index| array[index] = elem }
  else
    enum.each { array.push_back = _1 }
  end
  array
end

Instance Method Details

#each(&blk) ⇒ Object



39
40
41
42
43
# File 'lib/godot_rb/enumerable.rb', line 39

def each(&blk)
  return to_enum { size } unless blk
  size.times { blk.(self[_1]) }
  self
end