Hi,
In message "[ruby-talk:15234] Pluggable sorting - How would you do it?"
on 01/05/16, "Hal E. Fulton" <hal9000 / hypermetrics.com> writes:
|Passing a block to "sort" is neat, but it's a little more
|intrusive than I have in mind.
|
|I thought about a Proc object or something... but I ended
|up doing it this way (see code below).
|
|It works. But I'm sure many of you have better ideas.
|
|How would *you* do it?
GOTO Kentaro once proposed something like this.
a = x.sort_by{|x| x.str}
b = x.sort_by{|x| x.int}
c = x.sort_by{|x| x.chr}
It implements Schwartzian transformation inside. I like this idea,
but am not yet sure "sort_by" is a proper name for the behavior.
matz.