A lot of variables require some processing, so I'm checking if any of them are nil
. Is there a more efficient way of writing the following?
unless a.nil? || b.nil? || c.nil? || d.nil? || e.nil? || f.nil? || g.nil?
render 'view'
end
Or should I avoid checking a lot of variables for nil
on one line?
By using none?
you can have if
instead of unless
:
if [a,b,c,d,e,f,g].none?(&:nil?)
Come to think of it, this can be reduced to simply:
if [a,b,c,d,e,f,g].all?
if you don't mind treating false
the same as nil
Is there a more efficient way of writing the following?
I think a better question is, "Is there a more expressive way of writing..."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With