Class A has the following comparator:
A
class A attr_accessor x def my_comparator(a) x**2 <=> (a.x)**2 end end
Both of these should work:
items.sort_by! { |a| (a.x)**2 } items.sort! { |a1,a2| a1.my_comparator(a2) }