Issue #16425 has been reported by nobu (Nobuyoshi Nakada).

----------------------------------------
Feature #16425: Add Thread#dig
https://bugs.ruby-lang.org/issues/16425

* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
`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
```ruby
    def check_inspect_key(id)
      Thread.current[:__recursive_key__] &&
      Thread.current[:__recursive_key__][:inspect] &&
      Thread.current[:__recursive_key__][:inspect].include?(id)
    end
```

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

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




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>