Created
March 9, 2015 05:53
-
-
Save itang/13efb9db518cfa89a48e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Optimizing | |
def assert(cond) | |
if !cond | |
raise "Assert Failure" | |
end | |
end | |
def color_by_score(score) | |
assert (score >= 0 && score <= 100) | |
case | |
when score >= 80 && score <= 100 | |
"green" | |
when score >= 60 | |
"yellow" | |
when score >= 0 | |
"red" | |
end | |
end | |
end | |
o = Optimizing.new | |
(0..100).to_a.each do |i| | |
puts "#{i}: #{o.color_by_score(i)}" | |
end | |
begin | |
o.color_by_score 101 | |
rescue e: Exception | |
puts "Exception: #{e}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment