[ruby-core:96265] [Ruby master Feature#16425] Add Thread#dig
| Newsgroups | gmane.comp.lang.ruby.core |
|---|---|
| Message-ID | <redmine.issue-16425.20191216123854.7837120b7ebb6d66@ruby-lang.org> |
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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>