From: Christoph Schmitz Date: 2002-12-29T20:56:58+09:00 Subject: yield and recursion Hi all, I was just trying to grasp the concept of iterators, and the first thing I tried was an iterator for a binary tree. What I came up with is something like class Node .... def inorder @left.inorder unless @left.nil? yield @value @right.inorder unless @right.nil? end end @left, @right and @value being the obvious fields. This doesn't work as intended, though. (LocalJumpError IIRC). So I tried this: class Node .... def inorder_block (block) @left.inorder_block (block) unless @left.nil? block.call(@value) @right.inorder_block (block) unless @right.nil? end def inorder_yield inorder_block { |value| yield value } end end Now I can write aNode.inorder_yield { |v| ... do something with v ... } It looks to me that the second version is just an unrolled way of writing the first one. Can anyone tell me what the difference is? Thanks in advance, Christoph