From: Joel VanderWerf Date: 2006-05-02T04:27:29+09:00 Subject: Re: traversal of a tree + block code Andrew Gibson wrote: > Hi: > > I want to be able to traverse a tree and for each node perform some > random code...sounds like an ideal situation for blocks, right? :) > > My problem is that I'm not sure how to keep passing the code block in > the recursive call. This is my best attempt so far... i'm not very > strong in this area so any advice would be welcome! :) > > def self.depthFirstTraversal(parent , &block) > children = parent.children > children.each do |child| > block.call(child) Instead of... > self.depthFirstTraversal(child) do |node| > block.call(node) > end try this... depthFirstTraversal(child, &block) > end > end > -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407