Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Optimizing
  2.  
  3. def assert(cond)
  4. if !cond
  5. raise "Assert Failure"
  6. end
  7. end
  8.  
  9. def color_by_score(score)
  10. assert (score >= 0 && score <= 100)
  11.  
  12. case
  13. when score >= 80 && score <= 100
  14. "green"
  15. when score >= 60
  16. "yellow"
  17. when score >= 0
  18. "red"
  19. end
  20. end
  21. end
  22.  
  23. o = Optimizing.new
  24.  
  25. (0..100).to_a.each do |i|
  26. puts "#{i}: #{o.color_by_score(i)}"
  27. end
  28.  
  29. begin
  30. o.color_by_score 101
  31. rescue e: Exception
  32. puts "Exception: #{e}"
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement