Class: Twig::Node::Expression::Binary::Elvis
- Inherits:
-
Binary::Base
- Object
- Binary::Base
- Twig::Node::Expression::Binary::Elvis
- Includes:
- OperatorEscape
- Defined in:
- lib/twig/node/expression/binary/elvis.rb
Instance Method Summary collapse
- #compile(compiler) ⇒ Object
-
#initialize(left, right, lineno) ⇒ Elvis
constructor
A new instance of Elvis.
- #operand_names_to_escape ⇒ Object
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_escape ⇒ Object
28 29 30 |
# File 'lib/twig/node/expression/binary/elvis.rb', line 28 def operand_names_to_escape %i[left right] end |