Class: Twig::Node::Expression::Ternary

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

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

#initialize(test, left, right, lineno) ⇒ Ternary

Returns a new instance of Ternary.



9
10
11
12
13
14
15
# File 'lib/twig/node/expression/ternary.rb', line 9

def initialize(test, left, right, lineno)
  super({
    test:,
    left:,
    right:,
  }, {}, lineno)
end

Instance Method Details

#compile(compiler) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/twig/node/expression/ternary.rb', line 17

def compile(compiler)
  compiler.
    raw('(::Twig::Extension::Core.bool(').
    subcompile(nodes[:test]).
    raw(') ? (').
    subcompile(nodes[:left]).
    raw(') : (').
    subcompile(nodes[:right]).
    raw('))')
end

#operand_names_to_escapeObject



28
29
30
# File 'lib/twig/node/expression/ternary.rb', line 28

def operand_names_to_escape
  %i[left right]
end