Project

General

Profile

Actions

Feature #8246

closed

Hash#traverse

Added by zzak (zzak _) over 11 years ago. Updated about 10 years ago.

Status:
Closed
Target version:
-
[ruby-core:54160]

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

275.patch (3.05 KB) 275.patch zzak (zzak _), 04/11/2013 08:03 AM

Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #8237: Logical method chaining via inferred receiverClosedActions
Is duplicate of Ruby master - Feature #5531: deep_value for dealing with nested hashesClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0