-x[directory] Tells Ruby that the script is embedded in a message.
Leading garbage will be discarded until the first that
starts with “#!” and contains the string, “ruby”. Any
meaningful switches on that line will applied. The end of
script must be specified with either EOF, ^D (control-D),
^Z (control-Z), or reserved word __END__. If the direc‐
tory name is specified, Ruby will switch to that directory
before executing script.
STACK = []
class Label
attr_accessor :name;
attr_accessor :block;
def initialize(name, block);
@name = name
@block = block
end
def ==(sym)
@name == sym
end
end
class Goto < Exception;
attr_accessor :label
def initialize(label); @label = label; end
end
def label(sym, &block)
STACK.last << Label.new(sym, block)
end
def frame_start
STACK << []
end
def frame_end
frame = STACK.pop
idx = 0
begin
for i in (idx...frame.size)
frame[i].block.call if frame[i].block
end
rescue Goto => g
idx = frame.index(g.label)
retry
end
end
def goto(label)
raise Goto.new(label)
end
label_stack_main do
x = 0
label(:increment) do
x += 1
goto :example
end
label(:example) do
puts x
goto :increment if x < 10
end
label(:start) do
goto :example
end
end
5条答案
按热度按时间wlzqhblo1#
首先,它将是一个声明,而不是一个命令。第二,参见ruby-goto。三、注意事项
**类别:**图书馆/邪恶
ecr0jaav2#
Ruby命令行开关
-x
顺便说一句,我很确定ruby-goto是,嗯,一个笑话。我不相信下载链接曾经工作过。或者我应该指给别人看然后保持沉默?我不知道...
我喜欢Ryan在宣布ruby-goto之后的下一句话:
敬请期待下一个邪恶模块。。ruby-malloc!祝你今天愉快
瑞安显然是个天才。
lkaoscv73#
我不这么认为(而且,以神圣的名义,它不应该)。
但是如果你真的有受虐狂的感觉,有一个
goto
模块。xriantvc4#
后藤库仍然与我们同在:D https://rubygems.org/gems/goto/versions/0
为子孙后代保存整颗宝石:
shstlldc5#
我尝试创建一个gist来实现它的功能,this is how it went。
我的图书馆是如何工作的:
它的输出是:
请注意,我的库不以任何方式、形状或形式使用异常。另外,请注意,Ruby团队没有在语言中实现
goto
是有原因的,我做的这个东西只是为了好玩:)