Class: Yadriggy::ArrayRef

Inherits:
ASTnode
  • Object
show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb

Overview

Array reference.

Direct Known Subclasses

ArrayRefField

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ ArrayRef

Returns a new instance of ArrayRef.



1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# File 'lib/yadriggy/ast.rb', line 1018

def initialize(sexp)
  @array = to_node(sexp[1])
  args_block = sexp[2]
  if args_block.nil?
    @indexes = []
  else
    args = has_tag?(args_block, :args_add_block)[1]
    @indexes = to_nodes(args)
  end

  add_child(@array)
  add_children(@indexes)
end

Instance Attribute Details

#arrayASTnode (readonly)

Returns the array object.

Returns:



1010
1011
1012
# File 'lib/yadriggy/ast.rb', line 1010

def array
  @array
end

#indexesArray<ASTnode> (readonly)

Returns all the comma-separated indexes. It may be an empty array.

Returns:

  • (Array<ASTnode>)

    all the comma-separated indexes. It may be an empty array.



1014
1015
1016
# File 'lib/yadriggy/ast.rb', line 1014

def indexes
  @indexes
end

Class Method Details

.tagObject



1016
# File 'lib/yadriggy/ast.rb', line 1016

def self.tag() :aref end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



1035
1036
1037
# File 'lib/yadriggy/ast.rb', line 1035

def accept(evaluator)
  evaluator.array_ref(self)
end