有没有在指定行启动,像goto语句呢?
Answer 1:
首先,这将是声明,不是命令。 其次,看红宝石跳转 。 三,注意事项
类别:图书馆/邪恶
Answer 2:
有红宝石命令行开关-x
。
-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.
顺便说一句,我敢肯定红宝石转到了,嗯,开个玩笑。 我不相信的下载链接已经工作过。 还是我应该指向人,并保持安静? 我从来都不知道...
我喜欢Ryan的下一行宣布红宝石转到后:
敬请期待接下来的邪恶模块...红宝石的malloc! 祝你今天愉快。
瑞安显然是一个天才。
Answer 3:
我不这么认为(和,所有这神圣的,它不应该 )。
但是,有一个goto
如果你感觉真的很自虐它模块。
Answer 4:
goto语句LIB仍然和我们在一起:d https://rubygems.org/gems/goto/versions/0
节约为后人整个宝石:
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
文章来源: Is there goto statement in Ruby?