【发布时间】:2016-04-06 21:06:37
【问题描述】:
我有时会使用ActiveSupport中的#try:
1.try(:not_a_method)
#=> nil
耶!没有抛出异常,但假设我不想要 nil:
1.better_than_try(:not_a_method){0}
#=> 0
这存在吗?
【问题讨论】:
-
您始终可以编写自己的核心扩展,称为
try_or_whatever。
标签: ruby activesupport