在Ruby中抑制sure块的好方法是什么?

时间:2019-10-07 19:12:56

标签: ruby-on-rails ruby

def run
  ...

rescue FooError
  ...

rescue
  ...

ensure
  ...
end

如何仅针对FooError抑制sure块?

1 个答案:

答案 0 :(得分:4)

那呢?

def run
  ...

rescue FooError
  rescued_foo_error = true
  ...

rescue
  ...

ensure
  unless rescued_foo_error
    ...
  end
end