module Hashie::Extensions::DeepFetch

Searches a deeply nested datastructure for a key path, and returns the associated value.

options = { user: { location: { address: '123 Street' } } }
options.deep_fetch :user, :location, :address #=> '123 Street'

If a block is provided its value will be returned if the key does not exist.

options.deep_fetch(:user, :non_existent_key) { 'a value' } #=> 'a value'

This is particularly useful for fetching values from deeply nested api responses

or params hashes.