Logo

Programming-Idioms

History of Idiom 28 > diff from v17 to v18

Edit summary for version 18 by :

Version 17

2015-09-03, 15:17:21

Version 18

2015-09-03, 15:28:47

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