Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Created September 25, 2012 23:56
Show Gist options
  • Select an option

  • Save blasterpal/3785179 to your computer and use it in GitHub Desktop.

Select an option

Save blasterpal/3785179 to your computer and use it in GitHub Desktop.
Recursively count all keys or do something with a hash
def self.counth(thehash,count=0)
count += thehash.keys.size if thehash.is_a? Hash
thehash.keys.each do |key|
if thehash[key].is_a? Hash
count = counth(thehash[key],count)
end
end
count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment