更新时间:2023-11-25 16:08:16
Ruby 2.3.0 添加了一个安全导航操作符 (&.
),在调用之前检查 nil方法.
Ruby 2.3.0 added a safe navigation operator (&.
) that checks for nil before calling a method.
s&.strip
如果 s
是 nil
,这个表达式返回 nil
而不是引发 NoMethodError
.
If s
is nil
, this expressions returns nil
instead of raising NoMethodError
.