Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement