Logo

Programming-Idioms

History of Idiom 57 > diff from v35 to v36

Edit summary for version 36 by :
[Ruby] Use required variable names

Version 35

2016-02-18, 17:24:48

Version 36

2016-04-12, 20:30:08

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?)
Code
y = x.select(&:p)
Comments bubble
`select` is also aliased to `find_all`.
Comments bubble
`select` is also aliased to `find_all`.
Doc URL
http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-select
Doc URL
http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-select