I have an array of objects in Ruby on Rails. I want to sort the array by an attribute of the object. Is it possible?
I recommend using sort_by instead:
objects.sort_by {|obj| obj.attribute}
Especially if attribute may be calculated.
Or a more concise approach:
objects.sort_by(&:attribute)