From: Justin To Date: 2008-06-11T02:46:41+09:00 Subject: Re: Basic Tree Data Structure class Tree attr_reader :value def initialize(value) @value = value @children = [] end def <<(value) subtree = Tree.new(value) @children << subtree return subtree end end t = Tree.new("Parent") child1 = t << "Child 1" child2 = t << "Child 2" gc1 = child1 << "GC 1.1" class Tree def each puts "1" yield value puts "2" @children.each do |child_node| puts "in child_node" child_node.each { |e| puts "3"; yield e; } end end end t.each { |x| puts "t.each"; puts x } OUTPUT: 1 t.each Parent 2 in child_node 1 3 t.each Child 1 2 in child_node 1 3 # why are there two 3's here?? 3 # ????? Doesn't Child 1 only have one child in its array @children?? t.each GC 1.1 2 in child_node 1 3 t.each Child 2 2 (^ comment) Thanks in advance -- Posted via http://www.ruby-forum.com/.