From: Pete McBreen Date: 2002-04-13T12:12:32+09:00 Subject: Re: Rudy idiom for enumeranting parents of a node? Brad Cox wrote >I need to enumerate the parentage chain of the nodes in a >doubly-linked tree. No problem in C/Java, but I'm still too new to >Ruby to see how. Can someone help? I though that this one would be easy to answer until I realized that although there is a #block_given? method I don't know how to refer to an anonymous given block. A very crude hack is to say class Node def initialize(parent, children=[]) @parent = parent @children = children @children.each { |child| child.parent(self) } end def parents (*unused_args, &block) @parent.parents &block unless @parent.nil? yield self end end p = Node.new(nil) p2 = Node.new(p) p2.parents {|o| p o} If this isn't what you want please let me know Pete ---- Pete McBreen, McBreen.Consulting , Cochrane, AB email: petemcbreen@acm.org http://www.mcbreen.ab.ca/ Author, "Software Craftsmanship The New Imperative" Addison-Wesley (C) 2002 http://www.amazon.com/exec/obidos/ASIN/0201733862 Finalist for the 2002 Jolt Awards