[#115244] [Ruby master Feature#19987] add sample method to Range — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19987 has been reported by horv77@protonmail.com (Andras Horvath).
6 messages
2023/11/05
[#115247] [Ruby master Feature#19988] AI for inner code behavior analysis at runtime — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19988 has been reported by horv77@protonmail.com (Andras Horvath).
3 messages
2023/11/05
[#115404] Ruby 3.2.2 - rbconfig.rb's MAKEFILE_CONFIG — Jay Mav via ruby-core <ruby-core@...>
Hello Ruby Dev Team,
4 messages
2023/11/17
[ruby-core:115273] [Ruby master Feature#14602] Version of dig that raises error if a key is not present
From:
"sinsoku (Takumi Shotoku) via ruby-core" <ruby-core@...>
Date:
2023-11-06 14:16:41 UTC
List:
ruby-core #115273
Issue #14602 has been updated by sinsoku (Takumi Shotoku).
I agree with [#14602#note-23](https://bugs.ruby-lang.org/issues/14602#note-23).
I think a fetch-based or dig-based name would be better, since the function can be inferred from the method name.
Personally, I feel that **deep_fetch** is a simple and nice name.
I often use [deep_dup](https://api.rubyonrails.org/classes/Object.html#method-i-deep_dup) and [deep_merge](https://api.rubyonrails.org/classes/Hash.html#method-i-deep_merge) in Rails apps and are familiar with the method name `deep_*`.
I found `fetch_dig` and `dig_fetch` to be a little strange in that they have verbs lined up.
I think `dig_strict` is a good name, but I prefer **deep_fetch** because `deep` has fewer characters and is simpler than `strict`.
----------------------------------------
Feature #14602: Version of dig that raises error if a key is not present
https://bugs.ruby-lang.org/issues/14602#change-105189
* Author: amcaplan (Ariel Caplan)
* Status: Open
* Priority: Normal
----------------------------------------
Currently, if I have a hash like this:
~~~ ruby
{
:name => {
:first => "Ariel",
:last => "Caplan"
}
}
~~~
and I want to navigate confidently and raise a KeyError if something is missing, I can do:
~~~ ruby
hash.fetch(:name).fetch(:first)
~~~
Unfortunately, the length of the name, combined with the need to repeat the method name every time, means most programmers are more likely to do this:
~~~ ruby
hash[:name][:first]
~~~
which leads to many unexpected errors.
The Hash#dig method made it easy to access methods safely from a nested hash; I'd like to have something similar for access without error protection, and I'd think the most natural name would be Hash#dig!. It would work like this:
~~~ ruby
hash = {
:name => {
:first => "Ariel",
:last => "Caplan"
}
}
hash.dig!(:name, :first) # => Ariel
hash.dig!(:name, :middle) # raises KeyError (key not found: :middle)
hash.dig!(:name, :first, :foo) # raises TypeError (String does not have #dig! method)
~~~
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/