When the code would tell better than words:

[4] pry> Models::Company.order(:name).select_map(:name)
=> ["Dekker, Jacobs and Bosch", "Koster en Zonen", "Peters-Koster", "Peters, Vries and Smits", "Wal, Linden and Jacobs"]
[5] pry> Models::Company.order(:name).select_map(:name).sort
=> ["Dekker, Jacobs and Bosch", "Koster en Zonen", "Peters, Vries and Smits", "Peters-Koster", "Wal, Linden and Jacobs"]

Because of this my spec randomly failing. I can normalize arrays before comparing them, like this:

result_names.map { |s| s.gsub(/,|-/, '') }

I tried to sort the same array in JavaScript, and get the same result as Ruby gave me. I am wondering now, is there some sort of standard for sorting strings, or is it the detail of implementation?

share|improve this question
    
Is the dash in "Peters-Koster" ascii 45 or long dash? – DavidC 9 mins ago
    
Something to do with encoding or collation configuration of your Postgres server, perhaps? – Tom Lord 6 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.