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.



948
949
950
951
952
953
954
955
956
957
958
959
960
# File 'lib/yadriggy/ast.rb', line 948

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:



940
941
942
# File 'lib/yadriggy/ast.rb', line 940

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.



944
945
946
# File 'lib/yadriggy/ast.rb', line 944

def indexes
  @indexes
end

Class Method Details

.tagObject



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

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.



965
966
967
# File 'lib/yadriggy/ast.rb', line 965

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