这里是Bar#do_things
:
class Bar
def do_things
Foo.some_method(x) do |x|
y = x.do_something
return y_is_bad if y.bad? # how do i tell it to stop and return do_things?
y.do_something_else
end
keep_doing_more_things
end
end
这里是Foo#some_method
:
class Foo
def self.some_method(targets, &block)
targets.each do |target|
begin
r = yield(target)
rescue
failed << target
end
end
end
end
我考虑使用raise,但是我尝试使其通用化,所以我不想在Foo
中放置任何特定内容。
next
:下一个break
:中断return
:返回you can't compare
:你不能比较File.foreach(filename) { break if condition }
?这会让文件保持打开状态吗? - Redomanreturning control to the iterator method
。 - Sam YC