相关疑难解决方法(0)

SystemExit是一种特殊的异常吗?

如何SystemExit表现与其他Exceptions 不同?我想我明白了一些关于为什么它的推理不会是很好的提高适当的异常.例如,您不希望发生类似这样的奇怪事件:

begin
  exit
rescue => e
  # Silently swallow up the exception and don't exit
end
Run Code Online (Sandbox Code Playgroud)

怎么也该rescue忽略SystemExit?(它使用什么标准?)

ruby exception-handling exit

14
推荐指数
1
解决办法
6628
查看次数

在Ruby中构建长字符串的干净方法

在编写Ruby(客户端脚本)时,我看到了三种构建更长字符串的方法,包括行结尾,所有这些对我来说都"难闻".

有没有更清洁,更好的方法?

变量递增.

if render_quote?
  quote =  "Now that there is the Tec-9, a crappy spray gun from South Miami."
  quote += "This gun is advertised as the most popular gun in American crime. Do you believe that shit?"
  quote += "It actually says that in the little book that comes with it: the most popular gun in American crime."
  quote += "Like they're actually proud of that shit."
  puts quote
end
Run Code Online (Sandbox Code Playgroud)

Heredocs(和未公开的引用).

if render_quote?
  quote =<<EOS
Now that there …
Run Code Online (Sandbox Code Playgroud)

ruby string messages heredoc

5
推荐指数
1
解决办法
835
查看次数

标签 统计

ruby ×2

exception-handling ×1

exit ×1

heredoc ×1

messages ×1

string ×1