Skip to content

Instantly share code, notes, and snippets.

@saturday
Created December 7, 2016 02:33
Show Gist options
  • Save saturday/8738514199a7cb12b47b60b5c65b78bd to your computer and use it in GitHub Desktop.
Save saturday/8738514199a7cb12b47b60b5c65b78bd to your computer and use it in GitHub Desktop.
hash = {"one" => 2, "two" => 2, "three" => 3}
hash.sort_by do |k,v|
# I want to sort this hash starting at k["two"], and then go in any direction from there (asc or desc) using the key name.
end
@saturday
Copy link
Author

saturday commented Dec 7, 2016

hash.sort_by {|k,v| k == "one" ? 1 : 0 }.reverse.to_h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment