Project

General

Profile

Actions

Feature #16425

open

Add Thread#dig

Added by nobu (Nobuyoshi Nakada) almost 5 years ago. Updated almost 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:96265]

Description

Thread has #[] method like as Array, Hash, Struct and so on, but no #dig.

For instance, PP::PPMethods#check_inspect_key in pp.rb can be simplified with the combination of this method and safe navigation operator.

From

    def check_inspect_key(id)
      Thread.current[:__recursive_key__] &&
      Thread.current[:__recursive_key__][:inspect] &&
      Thread.current[:__recursive_key__][:inspect].include?(id)
    end

To

    def check_inspect_key(id)
      Thread.current.dig(:__recursive_key__, :inspect)&.include?(id)
    end

Patch: https://github.com/ruby/ruby/pull/2756

Actions

Also available in: Atom PDF

Like0
Like0