I have a hash like:
dict = {
"someKey" => [ ... ],
"anotherKey" => [ ... ],
"yetAnōtherKéy" => [ ... ]
}
I want a new hash by sorting the original. Sorting should ignore the accents (done by replacing the accented characters with their un-accented version),
replacements = [
["ā", "a"], ["á", "a"], ["à", "a"], ["ǎ", "a"],
["ō", "o"], ["ó", "o"], ["ò", "o"], ["ǒ", "o"],
["ī", "i"], ["í", "i"], ["ì", "i"], ["ǐ", "i"],
["ē", "e"], ["é", "e"], ["è", "e"], ["ě", "e"],
["ū", "u"], ["ú", "u"], ["ù", "u"], ["ǔ", "u"]
]
but the keys in the resulting hash should keep the original keys. How is that possible?
I tried
dict = Hash[dict.sort_by{|k,v| k}]
This works and does sort the hash. However, it doesn't ignore the accents, i.e., the words starting with an accented character go to the bottom.
Another attempt is:
replacements.each {|replacement| z.gsub!(replacement[0], replacement[1])}