DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Just Rescue If The Errors Cause Doesn't Matter
Sometimes we have to check for every possible error and react adequate, but only sometimes. There are also cases, where it does not matter what's wrong, the result we want in any error case is clear. Then we can just rescue. Here the occurrence array may not be set because nothing is counted yet, or one element is not set, because the according letter didn't occur yet, it does not matter. We always answer "The requested letter occurred 0 times till now."
def get_char_count(letterbyte) @occurrences[letterbyte].ccount rescue 0 end