Class: Enumerable::ByBreadthDelegator

Inherits:
TreeDelegator show all
Defined in:
lib/agents/sets/enum/tree.rb

Instance Attribute Summary

Attributes inherited from TreeDelegator

#args, #child_map, #child_name, #output_type, #root

Instance Method Summary collapse

Methods inherited from TreeDelegator

#get_children, #initialize

Methods included from Enumerable

#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe

Constructor Details

This class inherits a constructor from Enumerable::TreeDelegator

Instance Method Details

#each(level = [@root], &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/agents/sets/enum/tree.rb', line 49

def each level = [@root], &block

  children = []
  for node in level
    yield node
    children |= get_children(node) || []
  end
  
  if children and not children.empty?
    each children, &block
  end

  self
end