如果满足给定条件,则结束ruby程序

时间:2011-07-24 00:39:30

标签: ruby break ruby-1.9

基本上,如果满足某个条件,我只是试图阻止程序运行其余的行。

unless raw_information.first
  puts "No results were returned for that query"
  break
end

然而,在程序运行之前我得到了这个错误:

  

无效的休息   编译错误(SyntaxError)

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:11)

abort("No results were returned for that query") unless condition

unless condition
  abort("No results were returned for that query")
end