Skip to content

Instantly share code, notes, and snippets.

@wilson
Created August 25, 2009 03:28
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 wilson/174421 to your computer and use it in GitHub Desktop.
Save wilson/174421 to your computer and use it in GitHub Desktop.
# > {:x => 4, :y => 7}.keys_sorted_by_value
# [:y, :x]
class Hash
def keys_sorted_by_value
to_a.sort_by {|tuple| rand - tuple.last.to_i}.map {|tuple| tuple.first}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment