Class: TreeDelta::Traversal
- Inherits:
-
Enumerator
- Object
- Enumerator
- TreeDelta::Traversal
- Defined in:
- lib/tree_delta/traversal.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#initialize(direction:, order:) ⇒ Traversal
constructor
A new instance of Traversal.
- #traverse(node) ⇒ Object
Constructor Details
#initialize(direction:, order:) ⇒ Traversal
Returns a new instance of Traversal.
5 6 7 8 |
# File 'lib/tree_delta/traversal.rb', line 5 def initialize(direction:, order:) @direction = direction @order = order end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
3 4 5 |
# File 'lib/tree_delta/traversal.rb', line 3 def direction @direction end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
3 4 5 |
# File 'lib/tree_delta/traversal.rb', line 3 def order @order end |
Instance Method Details
#traverse(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tree_delta/traversal.rb', line 10 def traverse(node) Enumerator.new do |y| if node y.yield(node) if order == :pre ordered_children(node).each do |child| traverse(child).each { |n| y.yield(n) } end y.yield(node) if order == :post end end end |