Class: Twig::NodeVisitor::Spreader
- Defined in:
- lib/twig/node_visitor/spreader.rb
Overview
This visitor checks the contents of the Spread operator to see if it’s a hash or array. If it is, it converts it to a HashSpread or ArraySpread node.
The cases where this is not, would be some kind of variable expression which we cannot determine at compile time, and still need to be sent through the ArgumentSpreader so that they can be spread properly into the destination callable.
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#enter_node(node, env) ⇒ Object
12 13 14 |
# File 'lib/twig/node_visitor/spreader.rb', line 12 def enter_node(node, env) node end |
#leave_node(node, env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/twig/node_visitor/spreader.rb', line 16 def leave_node(node, env) unless node.is_a?(Node::Expression::Unary::Spread) return node end if node.nodes[:node].instance_of?(Node::Expression::Hash) return Node::Expression::Unary::HashSpread.new( node.nodes[:node], node.lineno ) end if node.nodes[:node].instance_of?(Node::Expression::Array) return Node::Expression::Unary::ArraySpread.new( node.nodes[:node], node.lineno ) end node end |