Actually it would be possible, although very ugly.

You need to evaluate in the context of the current instance (instance_eval) -not yield - the block you pass to the each method of your object (an array in this case).

Then you can define a print method that behaves like a coroutine (check out ruby fibers) and returns each element of your array.

Sorry I'm not writing code here, I'm using my cellphone.

Michal Sokol

On Jun 4, 2011, at 8:23 AM, Peter Hickman <peterhickman386 / googlemail.com> wrote:

> Probably not without changing Ruby itself.
>