No commit activity in last 3 years
No release in over 3 years
Deletes recursively every key-value pair from hash for which block evaluates to true.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
>= 0
~> 10.0
~> 3.0
 Project Readme

Hash Reject Recursively

Gem Version Code Climate Coverage Status Travis

Like Hash#reject but recursively.

Deletes recursively every key-value pair from hash for which block evaluates to true.

Installation

Add this line to your application's Gemfile:

gem 'hash_reject_recursively'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hash_reject_recursively

Usage

languages = {
  ruby: { lines: 100 },
  python: { lines: nil },
  java: { lines: nil },
  php: nil
}

new_hash = languages.deep_reject { |key, value| value.nil? }
# new_hash == { ruby: { lines: 100 }, python: {}, java: {} }

new_hash = languages.deep_reject { |key, value| value.blank? } # Rails example
# new_hash == { ruby: { lines: 100 } }

languages.deep_reject! { |key, value| value.nil? }
# languages == { ruby: { lines: 100 }, python: {}, java: {} }

Note 1: deep_reject! changes the original object

Note 2: .blank? in example above it's Rails implementation method.

License

The gem is available as open source under the terms of the MIT License.

Contributing

First of all, thank you for wanting to help!

  1. Fork it.
  2. Create a feature branch - git checkout -b more_magic
  3. Add tests and make your changes
  4. Check if tests are ok - rake spec
  5. Commit changes - git commit -am "Added more magic"
  6. Push to Github - git push origin more_magic
  7. Send a pull request! ❤️