Skip to content

Instantly share code, notes, and snippets.

@robpe
Created July 1, 2013 16:46
Show Gist options
  • Save robpe/5902503 to your computer and use it in GitHub Desktop.
Save robpe/5902503 to your computer and use it in GitHub Desktop.
Ruby goto (PoC)
module Kernel
require 'singleton'
require 'continuation'
class Env < Hash
include Singleton
def initialize
super
end
end
def label(name)
callcc { |cc| Env.instance[name] = cc }
end
def goto(name)
raise "Goto couldn't find label: #{name}" unless Env.instance.key?(name)
Env.instance[name].call
end
end
require './goto'
def goop(times, &blk)
label :loop
blk.call
goto :loop unless (times-=1).zero?
end
goop(10) {
puts 'Hi goto!'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment