[#104004] [Ruby master Feature#17883] Load bundler/setup earlier to make `bundle exec ruby -r` respect Gemfile — mame@...
Issue #17883 has been reported by mame (Yusuke Endoh).
21 messages
2021/05/24
[ruby-core:103867] [Ruby master Feature#11747] "bury" feature, similar to 'dig' but opposite
From:
pbondawork@...
Date:
2021-05-17 13:03:24 UTC
List:
ruby-core #103867
Issue #11747 has been updated by pbonda (Pavel Bonda).
I agree that Hash-only use case looks most relevant, and I was expecting ruby has something build in.
It would also be cool to have an ability to transform value using this method, like:
``` ruby
{ a: { b: { [] => '1' } } }.bury(:a, :b, []) { |value| value.to_i }
# => { :a => { :b => { [] => 1 } } }
```
Hope that once this proposal will be reconsidered
----------------------------------------
Feature #11747: "bury" feature, similar to 'dig' but opposite
https://bugs.ruby-lang.org/issues/11747#change-91993
* Author: dam13n (damien sutevski)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
In Matz's recent Rubyconf talk, he used this example for the new 'dig' feature coming in Ruby 2.3:
~~~ruby
# we want this
data[:users][0][:name]
# we can do this w/o nil errors
data.dig(:users, 0, :name)
~~~
What I'm proposing is a 'bury' feature that is the opposite of 'dig' in a sense. It inserts a value at an arbitrary depth, for example:
~~~ruby
data.bury(:users, 0, :name, 'Matz')
~~~
This will create a nested hash or an array automatically at each step if it doesn't already exist, and that can be inferred from the what the user is passing (such as a symbol or string for a hash or an integer for an array). It's similar to autovivification but more powerful!
This behavior is very common, at least in my experience, so a dry method built into Ruby would be awesome!
---Files--------------------------------
bury_examples.rb (1 KB)
--
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>