class Regexp::Expression::Subexpression
def traverse(include_self = false, &block)
- For terminal expressions, :visit is called once.
:exit upon exiting it.
- For subexpressions, :enter upon entering the subexpression, and
The event argument is passed as follows:
the expression, and the index of the expression within its parent.
block for each expression with three arguments; the traversal event,
Traverses the subexpression (depth-first, pre-order) and calls the given
def traverse(include_self = false, &block) return enum_for(__method__, include_self) unless block_given? block.call(:enter, self, 0) if include_self each_with_index do |exp, index| if exp.terminal? block.call(:visit, exp, index) else block.call(:enter, exp, index) exp.traverse(&block) block.call(:exit, exp, index) end end block.call(:exit, self, 0) if include_self self end