HashPath
Provides a simple interface to access hash paths.
The gem was written to help with specs so use in production code will have an unkonwn performance hit.
Installation
Add this line to your application's Gemfile:
gem 'path_spec'
And then execute:
$ bundle
Or install it yourself as:
$ gem install path_spec
Usage
Given the hash { 'foo' => { 'bar' => { 'baz' => 'hai' } } }
# Nil versions
my_hash.at_path("foo.bar.baz") #=> 'hai'
my_hash.at_path("foo.bar.barry") #=> nil
my_hash.at_path("not_a_key") #=> nil
# Or the raise version
my_hash.at_path!("foo.bar.baz") #=> 'hai'
my_hash.at_path!("foo.bar.barry") #=> raises
my_hash.at_path("not_a_key") #=> raises
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request