NavigableHash
NavigableHash was built as lightweight and quick way to navigate through a hash or array object using the familiar ruby dot notation. See 'Usage' below for examples. Keys as strings or symbols don't matter, its all included.
Installation
Add this line to your application's Gemfile:
gem 'navigable_hash'
And then execute:
$ bundle
Or install it yourself as:
$ gem install navigable_hash
Usage
(Check out the rspec tests for coverage examples)
Most basic usage:
test_hash = { :example_key => 'example value' }
navigable_hash = NavigableHash.new(test_hash)
navigable_hash.example_key
# => 'example_value'
More:
new_hash = { :second_key => { :inner_key => true }, :array_item => [{}, "string", :symbol] }
navigable_hash = NavigableHash.new(new_hash)
navigable_hash.second_key.inner_key
# => true
navigable_hash.array_item.last
# => :symbol
Call Agnostic (key as a string, symbol or dot notation):
new_hash = { "first_key" => "value 1" }
navigable_hash = NavigableHash.new(new_hash)
navigable_hash.first_key
navigable_hash[:first_key]
navigable_hash["first_key"]
# => "value 1"
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