Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kbaird/hash-selectors
A small set of select methods for Ruby Hashes
https://github.com/kbaird/hash-selectors
Last synced: about 1 month ago
JSON representation
A small set of select methods for Ruby Hashes
- Host: GitHub
- URL: https://github.com/kbaird/hash-selectors
- Owner: kbaird
- License: mit
- Created: 2014-06-11T19:33:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-22T16:55:09.000Z (about 10 years ago)
- Last Synced: 2024-09-13T01:45:59.054Z (2 months ago)
- Language: Ruby
- Size: 279 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
hash-selectors
==============A small set of select methods for Ruby Hashes
# select_by... (or filter_by...)
{a: 1, b: 2, c: 3}.filter_by_keys :a, :b # returns {a: 1, b: 2}
{a: 1, b: 2, c: 3}.select_by_keys :a, :b # returns {a: 1, b: 2}{a: 1, b: 2, c: 3}.filter_by_values 1, 3 # returns {a: 1, c: 3}
{a: 1, b: 2, c: 3}.select_by_values 1, 3 # returns {a: 1, c: 3}# reject_by...
{a: 1, b: 2, c: 3}.reject_by_keys :c # returns {a: 1, b: 2}{a: 1, b: 2, c: 3}.reject_by_values 2 # returns {a: 1, c: 3}
# partition_by...
{a: 1, b: 2, c: 3}.partition_by_keys :a, :b # returns [{a: 1, b: 2}, {c: 3}]{a: 1, b: 2, c: 3}.partition_by_values 1, 3 # returns [{a: 1, c: 3}, {b: 2}]
# values_for_keys
{a: 1, b: 2, c: nil}.values_for_keys :a, :c # returns [1, nil]# unfiltered_values_for_keys
{a: 1, b: 2, c: nil}.unfiltered_values_for_keys :a, :c, :d # returns [1, nil, nil]