Class: Twig::Node::Expression::AssignName

Inherits:
Name show all
Defined in:
lib/twig/node/expression/assign_name.rb

Direct Known Subclasses

Variable::AssignContext

Constant Summary

Constants inherited from Name

Name::SPECIAL_VARS

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods included from SupportDefinedTest

#define_test_enabled?, #enable_defined_test

Methods inherited from Base

#explicit_parentheses?, #set_explicit_parentheses

Methods inherited from Base

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

Constructor Details

#initialize(name, lineno) ⇒ AssignName

Returns a new instance of AssignName.

Parameters:

  • name (String)
  • lineno (Integer)


11
12
13
14
15
16
17
# File 'lib/twig/node/expression/assign_name.rb', line 11

def initialize(name, lineno)
  if %w[true false none null nil].include?(name.downcase)
    raise Error::Syntax.new("You cannot assign a value to \"#{name}\".", lineno, source_context)
  end

  super
end

Instance Method Details

#compile(compiler) ⇒ Object



19
20
21
22
23
24
# File 'lib/twig/node/expression/assign_name.rb', line 19

def compile(compiler)
  compiler.
    raw('context[').
    string(attributes[:name]).
    raw(']')
end