Class: Twig::Node::Expression::Binary::Elvis

Inherits:
Base show all
Includes:
OperatorEscape
Defined in:
lib/twig/node/expression/binary/elvis.rb

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#operator

Methods inherited from Twig::Node::Expression::Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

#initialize(left, right, lineno) ⇒ Elvis

Returns a new instance of Elvis.



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

def initialize(left, right, lineno)
  super

  nodes[:test] = left.dup
  left.attributes[:always_defined] = true
end

Instance Method Details

#compile(compiler) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/twig/node/expression/binary/elvis.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/binary/elvis.rb', line 28

def operand_names_to_escape
  %i[left right]
end