DeepFetch
Easily fetch values from nested ruby hashes.
Installation
$ gem install deep_fetch
Usage
require 'deep_fetch'
big_hash = {
:foo => {
:bar => [ 'a', 'b', 'c' ],
:baz => :boo
}
}
big_hash.deep_fetch(:foo, :baz) # :boo
big_hash.deep_fetch(:foo, :boo) # raises KeyError
big_hash.deep_fetch(:foo, :boo) { "not found" } # "not found"
big_hash.deep_fetch(:foo, :bar, 1) # also fetch nested array
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request