Class: ArrayCallNode
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(array, index) ⇒ ArrayCallNode
constructor
A new instance of ArrayCallNode.
Methods inherited from Node
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
#evaluate ⇒ Object
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 |