Skip to content

Instantly share code, notes, and snippets.

@ilpoldo
Created February 20, 2010 18:28
Show Gist options
  • Save ilpoldo/309812 to your computer and use it in GitHub Desktop.
Save ilpoldo/309812 to your computer and use it in GitHub Desktop.
One-liner to partition an hash
# Divides the hash in two, the half that meets the criteria and the one that does not.
yes, no = h.partition {|k,v| v>1}.map {|side| Hash[*side.flatten]}
Hash[*h.map {|k,v| [String(k).chop,v]}.flatten]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment