select_where

extends ruby array with select helpers


License
Other
Install
gem install select_where -v 1.1.0

Documentation

SelectWhere

Simple select helpers with standalone or extension APIs. Specify target values with simple values or Procs.

Install

Add the following line to your Gemfile:

gem 'select_where'
Methods
select_where / detect_where
require 'select_where'

arr = [{ a: 1 }, { a: 2 }]
SelectWhere.select(arr, { a: 2 }) # => [{ a: 2}]
SelectWhere.detect(arr, { a: 2 }) # => { a: 2}
SelectWhere.select(arr, { a: ->(v) { v > 0 } }) # => [{ a: 1 }, { a: 2 }]

require 'select_where/core_ext/array'
arr = [{ a: 1 }, { a: 2 }]
arr.select_where({ a: 2 }) # => [{ a: 2}]
arr.detect_where({ a: 2 }) # => { a: 2}
arr.select_where({ a: ->(v) { v > 0 } }) # => [{ a: 1 }, { a: 2 }]
fetch_map
require 'select_where'

arr = [{ a: 1 }, { a: 2 }, { b: 3 }]
SelectWhere.fetch_map(arr, :a, nil) # => [1, 2, nil]

require 'select_where/core_ext/array'
arr.fetch_map(:a, nil) # => [1, 2, nil]