Method: Immutable::Enumerable#grep
- Defined in:
- lib/immutable/enumerable.rb
#grep(pattern, &block) ⇒ Object
Search the collection for elements which are ‘#===` to item. Yield them to the optional code block if provided, and return them as a new collection.
27 28 29 30 31 |
# File 'lib/immutable/enumerable.rb', line 27 def grep(pattern, &block) result = select { |item| pattern === item } result = result.map(&block) if block_given? result end |