Skip to content

Instantly share code, notes, and snippets.

Created August 27, 2012 17:24
Show Gist options
  • Save anonymous/3490574 to your computer and use it in GitHub Desktop.
Save anonymous/3490574 to your computer and use it in GitHub Desktop.
Better way to handle divide-by-zero?
def score
score = num_questions_correct.to_f / num_questions_total.to_f
score = 0.0 unless score.finite?
score
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment