Class: Twig::Node::Expression::Array

Inherits:
Base
  • Object
show all
Includes:
SupportDefinedTest
Defined in:
lib/twig/node/expression/array.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #lineno, #nodes, #source_context, #tag

Instance Method Summary collapse

Methods included from SupportDefinedTest

#define_test_enabled?, #enable_defined_test

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

#empty?, #length, #template_name, #to_s

Constructor Details

#initialize(elements, lineno) ⇒ Array

Returns a new instance of Array.

Parameters:



13
14
15
# File 'lib/twig/node/expression/array.rb', line 13

def initialize(elements, lineno)
  super(elements, {}, lineno)
end

Instance Method Details

#add_element(value) ⇒ Object

Parameters:



18
19
20
# File 'lib/twig/node/expression/array.rb', line 18

def add_element(value)
  nodes.add(value)
end

#compile(compiler) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twig/node/expression/array.rb', line 22

def compile(compiler)
  if define_test_enabled?
    return compiler.repr(true)
  end

  compiler.
    raw('[').
    indent

  first = true

  values.each do |value|
    unless first
      compiler.raw(', ')
    end

    first = false

    compiler.
      subcompile(value)
  end

  compiler.
    outdent.
    raw(']')
end

#each_valueObject



53
54
55
# File 'lib/twig/node/expression/array.rb', line 53

def each_value(&)
  values.each(&)
end

#valuesObject



49
50
51
# File 'lib/twig/node/expression/array.rb', line 49

def values
  nodes.values
end