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?
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?
You can use || operator:
1.try(:not_a_method) || 0
#=> 0
برچسب:
نویسنده: استخدام کار