Skip to content

Instantly share code, notes, and snippets.

@tonekk
Created January 13, 2016 09:47
Show Gist options
  • Save tonekk/308d1dc02af0e22209a4 to your computer and use it in GitHub Desktop.
Save tonekk/308d1dc02af0e22209a4 to your computer and use it in GitHub Desktop.
lifes = 9
puts "Try to kill me, I got #{lifes} lifes!\n"
loop do
begin
sleep 1
rescue Exception => e
lifes = lifes - 1
if lifes == 0
puts "Bye bye, I'm dead"
exit
else
puts "You hit me, still got #{lifes} life#{lifes > 1 ? 's' : ''} :)\n"
end
end
end
@tonekk
Copy link
Author

tonekk commented Jan 13, 2016

Why you should never catch Exception in ruby

Execute this program and try to kill it with ctrl-c. You'll be surprised how sustainable a cat is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment