Class: Twig::Node::Expression::Test::Defined

Inherits:
Base show all
Defined in:
lib/twig/node/expression/test/defined.rb

Overview

Checks if an expression is defined

{{ var is defined }}

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

#initialize(node, name, arguments, lineno) ⇒ Defined

Returns a new instance of Defined.

Parameters:



15
16
17
18
19
20
21
22
23
# File 'lib/twig/node/expression/test/defined.rb', line 15

def initialize(node, name, arguments, lineno)
  unless node.is_a?(SupportDefinedTest)
    raise Error::Syntax.new('The "defined" test only works with simple variables.', lineno)
  end

  node.enable_defined_test

  super
end

Instance Method Details

#compile(compiler) ⇒ Object



25
26
27
28
# File 'lib/twig/node/expression/test/defined.rb', line 25

def compile(compiler)
  compiler.
    subcompile(nodes[:node])
end