Robert, thank you for the reply.

On Wed, Mar 30, 2011 at 7:59 PM, Robert Klemme
<shortcutter / googlemail.com> wrote:
>>  self.each{|x| x.reach{|y| yield y}}
>> This works but is not elegant.
>> Somebody has an idea?
>
> The approach is broken because the block is not carried through the
> recursion.

I read your previous post.  I like it.
It is elegant to useblock instead of yield and to add reach method to
Enumerable module.

I am curious about when my code does not work.
I tested the next script and it printed the same as your code.

class String
 remove_method(:each)
end

class Object
 def reach
   if(self.respond_to?(:each))
     self.each{|x| x.reach{|y| yield y}}
   else
     yield(self)
   end
 end
end

[["hoge", "huga"],["foo", "bar"]].reach { |myself|
 print myself
}

With a nested array, a new block is given to the next 'reach'.
So, I think, if I write this without recursion (of course impossible),
the whole prosess is like
   some_array.each{|x1| x1.each{|x2| x2.each{ .... xn.each {|myself|
print myself} ....}}}
and xn is an unnested array.

If I misunderstand something, or my program has a bug, please let me know.

Thanks.

Haruka YAGNI