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?
More elegant objects.sort_by(&:attribute), you can add on a .reverse if you need to switch the order.
objects.sort_by(&:attribute)
.reverse