Project

General

Profile

Actions

Feature #13123

closed

NilClass#dig

Added by sawa (Tsuyoshi Sawada) over 7 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:79052]

Description

We now have Hash#dig. We often have a variable that is either a hash or nil but we are not sure which. In such cases, it would be convenient if we can apply dig without conditioning on whether it is a hash or nil.

h = {a: 1}
h.dig(:a) # => 1

h = nil
h.dig(:a) # => nil
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0