On Sun, Nov 7, 2010 at 1:15 PM, Michel Demazure <michel / demazure.com> wrote:
> Ammar Ali wrote in post #959889:
>
>> If I understood your issue correctly,
> Yes, it is exactly that. Your example shows it :
>
> a = [["g", 3], ["c", 3], ["a", 3], ["f", 3], ["e", 2], ["d", 3], ["b",
> 1]]
> b = a.sort_by{ |letter, number| letter}
> # = > [["a", 3], ["b", 1], ["c", 3], ["d", 3], ["e", 2], ["f", 3], ["g",
> 3]]
> c = b.sort_by{ |letter, number| number}
> # = > [["b", 1], ["e", 2], ["d", 3], ["c", 3], ["a", 3], ["f", 3], ["g",
> 3]]
>
>> Without code, I have to guess
> The code for sort_by refers to ruby_qsort
>
> I think a built-in sort method should be stable (or have a stable
> variant).

Thanks for the clarification, now I understand what you mean. Based on
the results of your example, it appears that ruby's qsort is naive.
AFAIK, the majority of qsort implementations are.

Maybe this is a question/request for the core mailing list.

Regards,
Ammar