rails/rails — pull request #9020 by tylerdooling (2013-01-21 20:02:10+00:00)
Title: Add Hash#traverse for clean nested access.

Traverses the given levels of a hash and returns the value associated with the
last key provided. Allows for concise access for deeply nested hashes.

hash = { level1: { level2: { level3: 3 } } }
hash.traverse :level1, :level2, :level3 #=> 3

Also supports a default value block if the value is nil or the key is
not found.

hash.traverse(:level1, :level2, :non_existent_key) { 5 } #=> 5