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

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

Instance Method Summary collapse

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