Skip to content

Instantly share code, notes, and snippets.

@sgonyea
Created June 28, 2012 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgonyea/3013462 to your computer and use it in GitHub Desktop.
Save sgonyea/3013462 to your computer and use it in GitHub Desktop.
def hash_counter(default=nil)
Hash.new{ |k,v| k[v] = block_given? ? yield : default }
end
counts = {
:sl => {
:absent => hash_counter(0),
:missing_data => hash_counter { hash_counter(0) },
:present_data => hash_counter { hash_counter(0) },
},
:sm => {
:absent => hash_counter(0),
:missing_data => hash_counter { hash_counter(0) },
:present_data => hash_counter { hash_counter(0) },
},
:sv => {
:absent => hash_counter(0),
:missing_data => hash_counter { hash_counter(0) },
:present_data => hash_counter { hash_counter(0) },
},
:missing_data => hash_counter(0),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment