Programming-Idioms

History of Idiom 28 > diff from v17 to v18

Edit summary for version 18 :

Version 17

Version 18

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of type Item of the objects in items.

Code
items.sort_by(&:p)
Doc URL
http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-sort_by