Logo

Programming-Idioms

History of Idiom 57 > diff from v21 to v22

Edit summary for version 22 by :

Version 21

2015-09-03, 13:57:56

Version 22

2015-09-03, 15:25:09

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Code
odd_numbers = (1..99).select { |number| number.odd? }
# OR shorter
odd_numbers = (1..99).select(&:odd?)
Comments bubble
`select` is also aliased to `find_all`.
Doc URL
http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-select