Skip to content

Instantly share code, notes, and snippets.

@itang
Created March 9, 2015 05:53
Show Gist options
  • Save itang/13efb9db518cfa89a48e to your computer and use it in GitHub Desktop.
Save itang/13efb9db518cfa89a48e to your computer and use it in GitHub Desktop.
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