From: pbondawork@... Date: 2021-05-17T13:03:24+00:00 Subject: [ruby-core:103867] [Ruby master Feature#11747] "bury" feature, similar to 'dig' but opposite 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: