On Sat, Feb 10, 2007 at 08:23:23AM +0900, Garance A Drosehn wrote:
> On 2/9/07, Garance A Drosehn <drosihn / gmail.com> wrote:
> >
> >
> >Besides, I wanted something which works for *any* routine which
> >takes a code-block, not just objects of type Array.  How could you
> >make that work for the each_pair method of Hash objects?
> >
> >I was thinking there should be some "big-picture" solution possible,
> >one which would work for all methods which take a code-block
> >parameter.  That is probably too complicated a goal, but at least a
> >solution which would work for some large subset of those methods.
> 
> 
> I should also say that I am not looking for a quick-fix for some
> specific script that I am writing.  This is more of a "blue-sky" topic,
> where I am thinking that maybe some future version of ruby could
> introduce a new feature for these situations.
> 
> I think the kind of solution that I'm looking for would require a change
> to ruby itself.  However, I also realize that I may have missed some
> features which are already in ruby, and which already do exactly what
> I want.
> 
require 'generator'
require 'enumerator'

g = Generator.new([1,2,3])

until g.end?
  p g.next
end

def happy
  yield 1
  yield 2
  yield 3
end

g2 = Generator.new(Enumerable::Enumerator.new(self, :happy))

until g2.end
  p g2.next
end

> -- 
> Garance Alistair Drosehn     =             drosihn / gmail.com
> Senior Systems Programmer
> Rensselaer Polytechnic Institute;             Troy, NY;  USA