なんと pure Ruby でここまで goto らしく! 画面右側は隠して御覧ください。
require 'goto'
__{
_ :hata1 do
cls
goto :hata3 end
_ :hata2 do
mes "はーい、こんにちは" end
_ :hata3 do
mes "旗を立ててみるテストです"
stop end}
……だめだろーなー……。
ちなみに goto.rb はこんなの。
class GotoEnviron
def initialize
@blocks = nil
@table = {}
end
def push_block(flag, block)
b = Block.new(block)
if @blocks
@blocks.last.next = b
else
@blocks = b
end
@table[flag] = b
end
def exec
b = @blocks
while true
target = catch(:__goto_environ_jump) {
while b
b.call
b = b.next
end
return
}
break unless target
raise ArgumentError, "no such flag: #{target}" unless @table[target]
b = @table[target]
end
end
def goto(target)
throw :__goto_environ_jump, target
end
class Block
def initialize(block)
@block = block
@next = nil
end
def call
@block.call
end
attr_accessor :next
def last
b = self
while b.next
b = b.next
end
b
end
end
end
def __
@env = GotoEnviron.new
yield
@env.exec
end
def _(flag, &block)
@env.push_block flag, block
end
def goto(target)
@env.goto target
end
(21:36)