## From http://gnuu.org/2009/03/21/demystifying-continuations-in-ruby/ require "continuation" # This use of continuation resembles the "break" operator, breaking out of a block # and skipping the code before the "break" and the block's end def main i = 0 callcc do |cc| # callcc gives us cc (called "label" in the original code), a continuation. # The do block executes with it as argument; cf. (call/cc (lambda (cc) ..)) puts i puts cc cc.call # this call immediately goes to where callcc's value belongs (that value is discarded: # no expression catches it) i = 1 # this future is not reached end puts i # execution comes here next, having discarded the value returned by callcc's block end main