Method: Twig::Node::Expression::Binary::StartsWith#compile

Defined in:
lib/twig/node/expression/binary/starts_with.rb

#compile(compiler) ⇒ Object



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

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

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