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.
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
#evaluate ⇒ Object
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 |