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.



61
62
63
64
# File 'lib/nodes/stmtnodes.rb', line 61

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

Instance Method Details

#evaluateObject



66
67
68
69
70
71
72
73
# File 'lib/nodes/stmtnodes.rb', line 66

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]
  @value
end