Project

General

Profile

Feature #16425

Add Thread#dig

Added by nobu (Nobuyoshi Nakada) 12 months ago. Updated 12 months ago.

Status:
Open
Priority:
Normal
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

Also available in: Atom PDF