Class: Twig::Node::Expression::Binary::EndsWith

Inherits:
Base show all
Defined in:
lib/twig/node/expression/binary/ends_with.rb

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#initialize, #operator

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

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from Twig::Node::Expression::Binary::Base

Instance Method Details

#compile(compiler) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/twig/node/expression/binary/ends_with.rb', line 8

def compile(compiler)
  left = compiler.var_name
  right = compiler.var_name

  compiler.
    raw("(#{left} = ").
    subcompile(nodes[:left]).
    raw(').respond_to?(:end_with?) && ').
    raw("(#{right} = ").
    subcompile(nodes[:right]).
    raw(").respond_to?(:end_with?) && (#{left}.end_with?(#{right}))")
end