I have a method here that takes an array of strings and groups the ones that are anagrams of each other together, with each group forming a sub-array of the main anagr
test_words.group_by{|w| w.each_char.sort}.values
would give
[
["cars", "racs", "scar"],
["for"],
["potatoes"],
["four"],
["creams", "scream"]
]
I modified sawa's answer slightly in order to ignore case and make sure there's no duplicate values:
test_words.group_by{|w| w.downcase.each_char.sort}.values.each{|v| v.uniq!}
I realize this will still give duplicates in the output if the words have characters with different cases, but that's fine for my purposes. Now I'm all sorted, thanks!