Last active
December 14, 2015 22:48
-
-
Save rummelonp/5160570 to your computer and use it in GitHub Desktop.
!!! goto !!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'continuation' | |
module Kernel | |
def labels | |
$labels ||= {} | |
end | |
def label(name) | |
callcc { |c| labels[name] = c } | |
end | |
def goto(name) | |
labels[name].call | |
end | |
end | |
i = 0 | |
label 10 | |
puts i += 1 | |
goto 10 if i < 10 | |
label :nyan | |
puts i -= 1 | |
goto :nyan if i > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment