Class: Hexp::Node::Rewriter
- Inherits:
-
Object
- Object
- Hexp::Node::Rewriter
- Includes:
- Hexp
- Defined in:
- lib/hexp/node/rewriter.rb
Overview
Create a new Hexp node based on an existing node
Rewriting in this case means iterating over the whole Hexp tree, and for each element providing zero or more elements to replace it with.
Constant Summary
Constants included from Hexp
Instance Method Summary collapse
-
#initialize(node, block) ⇒ Rewriter
constructor
Initialize a rewriter with the node to operate on, and the action.
-
#to_hexp ⇒ Hexp::Node
Implicit Hexp conversion protocol.
Methods included from Hexp
Constructor Details
#initialize(node, block) ⇒ Rewriter
Initialize a rewriter with the node to operate on, and the action
19 20 21 |
# File 'lib/hexp/node/rewriter.rb', line 19 def initialize(node, block) @node, @block = node, block end |
Instance Method Details
#to_hexp ⇒ Hexp::Node
Implicit Hexp conversion protocol
A Hexp::Node::Rewriter is lazy, only when one of the DSL methods is used, does the rewriting happen.
31 32 33 34 35 36 37 |
# File 'lib/hexp/node/rewriter.rb', line 31 def to_hexp @hexp ||= H[ @node.tag, @node.attributes, @block ? rewrite_children : @node.children ] end |