From: Fearless Fool Date: 2010-12-27T23:52:50+09:00 Subject: Re: converting traversal fn into Enumeration Robert Klemme wrote in post #970861: > Is this really the order that you want? Typically the current node is > visited between left and right to get an in order tree traversal: [snip] > Since you yield node instances themselves in #traverse it seems more > natural to implement #each like this: > > class TNode > include Enumerable > def each(&b) > left.each(&b) if left > yield value > right.each(&b) if right > self # according to convention of #each > end > end > Hi Robert: I like your refinement of using each() and returning self -- makes good sense. In this case, I actually want post-order (not in-order) traversal, but that's a trivial modification. Thanks. - ff -- Posted via http://www.ruby-forum.com/.