From: John Sikora Date: 2010-10-14T15:21:21+09:00 Subject: Re: setting local variables in a binding By the way, I've been busy and not checking the forums too much lately. However, I just noticed the concurrent thread of: sort_by: multiple fields with reverse sort. http://www.ruby-forum.com/topic/224672#new In my world I would do: class B < EnumerableObjectClass::Base attr_accessor :field_1, :field_0, :field_2 # sets default sort order. def initialize(field_0, field_1, field_2) super() @field_0, @field_1, @field_2 = field_0, field_1, field_2 end end B.new("radio", 30, 5) B.new("radio", 20, 5) B.new("archie", 20, 5) B.new("newton", 10, 3) # default sort - :field_1, field_0, field_2 order, normal direction. p B.enum{}.sort.collect(:field_0, :field_1, :field_2) # => [["newton", 10, 3], ["archie", 20, 5], ["radio", 20, 5], ["radio", 30, 5]] # sort by field_1 reverse, field_0 normal (same as the OP 3rd sort_by in that thread). p B.enum{}.sort(':field_1___', :field_0).collect(:field_0, :field_1, :field_2) # => [["radio", 30, 5], ["archie", 20, 5], ["radio", 20, 5], ["newton", 10, 3]] # sort by field_0 reverse, field_2 normal, field_1 reverse. p B.enum{}.sort(':field_0___', :field_2, ':field_1___').collect(:field_0, :field_1, :field_2) # => [["radio", 30, 5], ["radio", 20, 5], ["newton", 10, 3], ["archie", 20, 5]] Easy! Note the triple underscore suffix denotes reverse order sorting for that parameter. But this code uses the evil eval. js -- Posted via http://www.ruby-forum.com/.