Ruby 2.3.0 introduced a new method called dig on both Hash and Array that solves this problem entirely.
value = structure.dig(:a, :b)
It returns nil if the key is missing at any level.
If you are using a version of Ruby older than 2.3, you can use the ruby_dig gem.