[#122973] [PATCH] Add Gem.default_install — Felipe Contreras via ruby-core <ruby-core@...>
We need a way to enable user installs by default so that tools like
3 messages
2025/08/17
[ruby-core:123068] [Ruby Feature#12282] Hash#dig! for repeated applications of Hash#fetch
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2025-08-25 20:21:14 UTC
List:
ruby-core #123068
Issue #12282 has been updated by Eregon (Benoit Daloze).
Agreed `deep_fetch` is good.
Also wanted to mention `dig_fetch` from https://bugs.ruby-lang.org/issues/14602#note-16, there is even [a blog post about it](https://shopify.engineering/dig-fetch-truffleruby) so I think that illustrates it's a common name for this functionality.
What this issue wants is `dig` with `fetch` semantics instead of `[]` semantics, hence `dig_fetch`.
`fetch_path` doesn't seem ideal to me because this method would also be used e.g. with arrays and `object.fetch_path(:foo, 2, :baz)` doesn't really sounds like a "path".
Similarly, `deep_fetch` looks nice but doesn't make the relation to `dig` as clear as `dig_fetch`.
It could be `obj.dig(:foo, 2, :baz, exception: true)` I guess, but that's very verbose.
----------------------------------------
Feature #12282: Hash#dig! for repeated applications of Hash#fetch
https://bugs.ruby-lang.org/issues/12282#change-114381
* Author: robb (Robb Shecter)
* Status: Open
----------------------------------------
A new feature for your consideration: #dig! which is to #fetch as #dig is to #[]. For me and maybe many others, Hash#fetch is used much more than Hash#[]. And traversing multiple fetches isn't very convenient nor Ruby-like, e.g.: places.fetch(:countries).fetch(:canada).fetch(ontario).
Here's how it would work:
~~~ruby
places = { countries: { canada: true } }
places.dig :countries, :canada # => true
places.dig! :countries, :canada # => true
places.dig :countries, :canada, :ontario # => nil
places.dig! :countries, :canada, :ontario # => KeyError: Key not found: :ontario
~~~
Here's an implementation and tests: https://gist.github.com/dogweather/819ccdb41c9db0514c163cfdb1c528e2
--
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/lists/ruby-core.ml.ruby-lang.org/