From: "Hans Jörg Hessmann" Date: 2003-03-17T03:29:28+09:00 Subject: Iterator using Continuations Hi, Im am preparing a small presentation for ruby. Therefore I was searching for a continuation example. I tried to make a Java like iterator for any ruby class with an each() method. This is the solution I found: class Iterator def initialize(enum) @enum = enum @current = nil @back = nil @enum.each do |el| @current = el callcc do |cc| @next = cc if @back then @back.call else return end end end @current = nil @back.call if @back end def hasNext? @current != nil end def next last = @current callcc do |cc| @back = cc @next.call if @current end last end end iter = Iterator.new(1..5) while iter.hasNext? puts iter.next end What do you think of this approach? Is there an easier way to do it? Best regards, Hans J�rg Hessmann