خرید بک لینک

Vote count: 0

I sometimes use #try from ActiveSupport

1.try(:not_a_method) => nil

Yaay! No exceptions thrown, but let's say I don't want nil

1.better_than_try(:not_a_method){0} => 0

Does this exist?

asked 1 min ago

1 Answer

Vote count: 0

You can use || operator:

1.try(:not_a_method) || 0
#=> 0

answered just now

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 19 فروردين 1395 ساعت: 4:20

صفحه بندی