backport_dig is the backport of Hash#dig, Array#dig and OpenStruct#dig in Ruby 2.3 to older Ruby versions.
The best way is to use Ruby 2.3 or later. Because you can use original dig methods and so on.
Add these lines to your application's Gemfile:
gem 'backport_dig'
And then execute:
$ bundle
Or install it yourself as:
$ gem install backport_dig
And require it as:
require 'backport_dig'
h = {foo: {bar: {baz: 1}}}
h.dig(:foo, :bar, :baz) #=> 1
a = [[1, [2, 3]]]
a.dig(0, 1, 1) #=> 3
- Ruby 2.0
- Ruby 2.1
- Ruby 2.2
- Struct#dig is not supported
- 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
backport_dig is released under the MIT License.
- Hash#dig and Array#dig https://github.com/ruby/ruby/commit/2986268
- OpenStruct#dig https://github.com/ruby/ruby/commit/4825306
- Ruby Development Team
- Pay homage to ruby_dig