title: Ruby way: catch division by zero
body: <p>I have the following method to compute an average:</p>
  
  <pre><code>def compute_average(a,b,c,d,e)
    total = [a,b,c,d,e].sum.to_f
    average = [a, 2*b, 3*c, 4*d, 5*e].sum / total
    average.round(2)
  end
  </code></pre>
  
  <p>It's nothing special, but it has a problem that I expect all average equations have: it might divide by zero if inputs are all zero.</p>
  
  <p>So, I thought of doing this:</p>
  
  <pre><code>def compute_average(a,b,c,d,e)
    total = [a,b,c,d,e].sum.to_f
    if total==0
      average = 0.00
    else
      average = [a, 2*b, 3*c, 4*d, 5*e].sum / total
      average.round(2)
    end
  end
  </code></pre>
  
  <p>... and that works, but it feels kludgy to me. Is there a more elegant, "Ruby Way" to avoid this division by zero problem?</p>
  
  <p>What I'm wishing I had was an "unless then" operator, like...</p>
  
  <pre><code>average = numerator / denominator unless denominator == 0 then 0
  </code></pre>
  
  <p>Any suggestions?</p>