Class: ArrayCallNode

Inherits:
Node
  • Object
show all
Defined in:
lib/nodes/stmtnodes.rb

Instance Attribute Summary

Attributes inherited from Node

#value

Instance Method Summary collapse

Methods inherited from Node

#to_s

Constructor Details

#initialize(array, index) ⇒ ArrayCallNode

Returns a new instance of ArrayCallNode.



33
34
35
36
# File 'lib/nodes/stmtnodes.rb', line 33

def initialize(array, index)
  super(array)
  @index = index.to_i
end

Instance Method Details

#evaluateObject



38
39
40
41
42
43
44
# File 'lib/nodes/stmtnodes.rb', line 38

def evaluate
  arr = ScopeManager.lookup_var(@value)
  if @index > arr.size - 1
    raise ArgumentError, "You are trying to access an out of bounds index. Here -> #{@value}[#{@index}]"
  end
  @value = arr[@index]
end