-
-
Save saturday/8738514199a7cb12b47b60b5c65b78bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hash.sort_by {|k,v| k == "one" ? 1 : 0 }.reverse.to_h