ruby_dig2

Enhanced Array#dig and Hash#dig implementation.


License
MIT
Install
gem install ruby_dig2 -v 0.0.1

Documentation

RubyDig2

Hash#dig2 and Array#dig2 enhances Rubys Hash#dig and Array#dig methods functionality.

Installation

Add this line to your application's Gemfile:

gem 'ruby_dig2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruby_dig2

Usage

require 'ruby_dig2'

response = {mom: {first: "Marge", last: "Bouvier"},
            dad: {first: "Homer", last: "Simpson"},
            kids: [
                {first: "Bart", last: "Simpson"},
                {first: "Lisa", last: "Simpson"}
            ]}

response.dig2(:kids, 1, :first)
# => "Lisa"

Or finding the first detected element in array of hashes.

require 'ruby_dig2'

response = {mom: {first: "Marge", last: "Bouvier"},
            dad: {first: "Homer", last: "Simpson"},
            kids: [
                {first: "Bart", last: "Simpson"},
                {first: "Lisa", last: "Simpson"}
            ]}

response.dig2(:kids, {first: 'Lisa'}, :last)
# => "Simpson"

Contributing

  1. Fork it ( https://github.com/leoc/ruby_dig2/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request