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

Inherits:
Base
  • Object
show all
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

#template_name

Constructor Details

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

Returns a new instance of Ternary.



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

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

Instance Method Details

#compile(compiler) ⇒ Object



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

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