Issue #11747 has been updated by schwad (Nick Schwaderer).


I think the issues/problems specified in the comments are not present with a Hash-only implementation. :)

I would be supportive of re-considering this feature just for use with a Hash, where I believe 80% of the real-life use cases would (and do) exist. I have encountered this need before in the wild, but not with Arrays. In fact, I'm only here because it seems like something one would 'expect' ruby already to do. 

Thanks much for hearing me out. 

----------------------------------------
Feature #11747: "bury" feature, similar to 'dig' but opposite 
https://bugs.ruby-lang.org/issues/11747#change-85127

* 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>