#dig
lets you easily traverse nested hashes, arrays, or even a mix of them. It returns nil
if any intermediate value is missing.
x = {
foo: {
bar: [ 'a', { baz: 'x' } ]
}
}
x.dig(:foo, :bar) # => [ 'a', { baz: 'x' } ]
x.dig(:foo, :bar, 1, :baz) # => "x"
x.dig(:foo, :wronk, 1, :baz) # => nil
There is a tiny gem that backports this Show archive.org snapshot .
Posted by Dominik Schöler to makandra dev (2016-07-08 14:18)