Feature #8246
closedHash#traverse
Description
=begin
From ((<GH-275|URL:https://github.com/ruby/ruby/pull/275>))
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 - often encountered with dealing with external restful apis.
(({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}))
=end
Files
Updated by marcandre (Marc-Andre Lafortune) over 11 years ago
- Assignee set to matz (Yukihiro Matsumoto)
- Priority changed from Normal to 3
Updated by headius (Charles Nutter) over 11 years ago
As a feature that affects all Ruby implementations, this should probably move to CommonRuby: https://bugs.ruby-lang.org/projects/common-ruby
Updated by zzak (zzak _) about 10 years ago
- Status changed from Open to Closed
- Priority changed from 3 to Normal
Yeah, sorry, this is a duplicate of #5531 with just a different method name