On Wed, Mar 30, 2011 at 9:36 PM, Robert Klemme
<shortcutter / googlemail.com> wrote:
> On Wed, Mar 30, 2011 at 2:14 PM, Haruka YAGNI <hyagni / gmail.com> wrote:
>> Robert, thank you for the reply.
>>
>> On Wed, Mar 30, 2011 at 7:59 PM, Robert Klemme
>> <shortcutter / googlemail.com> wrote:
>>>> =A0self.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. =A0I 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
>> =A0remove_method(:each)
>> end
>
> I'm afraid the bug is in my brain. =A0You are right. =A0I am sorry. =A0I
> should have taken more time to look at this.

No problem at all.

> That approach does produce awful call stacks though (with multiple
> levels of nesting the call chain has to go backwards up to the topmost
> caller to invoke the block initially provided to reach; you can see
> this by adding "puts caller" to the beginning of the block). I find it
> more elegant to pass the block down and have it invoked immediately.
> Apparently you agree with me here.

Yes, I agree at all points.
When I do something like this in my application, I will use your
solution with appreciation.

Thank you for you kind information.


regards

Haruka YAGNI