I am trying to sort an array of words in Ruby 1.8.7 by an insane set of rules. This can be simplified to wanting to sort case-insensitive .sort_by{|a| a.downcase} then re-sort case-sensitive but only if the 2 strings are the same.
I would think you could just .downcase compare only the strings that are equal and then sort just those, sending 0 for the rest. But no, that isn't working for me.
Here's what I have:
["A", "a", "a.", "A.", "Ba", "ba"].sort_by{|a| a.downcase}.sort{|a,b| a.downcase==b.downcase ? a<=>b : 0 }
Desired output:
["A", "a", "A.", "a.", "Ba", "ba"]
Thanks for your help.