Class: Yadriggy::ArrayLiteral

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

Overview

Array literal.

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_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string

Constructor Details

#initialize(sexp) ⇒ ArrayLiteral

Returns a new instance of ArrayLiteral.



436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/yadriggy/ast.rb', line 436

def initialize(sexp)
  if sexp[1].nil?
    @elements = []
  elsif is_percent_literal(sexp[1])
    @elements = sexp[1].map do |e|
      StringInterpolation.new([:string_literal, [:string_content] + e])
    end
  else
    @elements = to_nodes(sexp[1])
  end
  add_children(@elements)
end

Instance Attribute Details

#elementsArray<ASTnode> (readonly)

Returns the array elements.

Returns:

  • (Array<ASTnode>)

    the array elements.



432
433
434
# File 'lib/yadriggy/ast.rb', line 432

def elements
  @elements
end

Class Method Details

.tagObject



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

def self.tag() :array 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.



452
453
454
# File 'lib/yadriggy/ast.rb', line 452

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

#const_valueObject



279
280
281
# File 'lib/yadriggy/ast_value.rb', line 279

def const_value()
  elements.map {|e| e.const_value }
end

#valueObject



271
272
273
# File 'lib/yadriggy/ast_value.rb', line 271

def value()
  elements.map {|e| e.value }
end

#value_in_class(klass) ⇒ Object



275
276
277
# File 'lib/yadriggy/ast_value.rb', line 275

def value_in_class(klass)
  elements.map {|e| e.value_in_class(klass) }
end