From: mikhail.krainik@... Date: 2017-03-14T12:55:43+00:00 Subject: [ruby-core:80155] [Ruby trunk Feature#13314] dig= Issue #13314 has been updated by Mikr (Mikhail Krainik). you can do that, as example ~~~ ruby a = {key1: { key2: { key3: { key4: '4' }}}}; a.dig(:key1, :key2, :key3)[:key4] = 4 # => {:key1=>{:key2=>{:key3=>{:key4=>4}}}} ~~~ ---------------------------------------- Feature #13314: dig= https://bugs.ruby-lang.org/issues/13314#change-63593 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- We have `Hash#dig`, and when we want to assign a key-value at a deep level, it is tempting to do: ```ruby hash.dig(:key1, :key2, :key3, :key4) = "value ``` when we actually needed to do: ```ruby hash.dig(:key1, :key2, :key3)&.[]=(:key4, "value") ``` I propose a method `Hash#dig=`, which should be equivalent to the following: ```ruby class Hash def dig=(*keys, final_key, value) dig(*keys)&.[](final_key, value) end end ``` -- https://bugs.ruby-lang.org/ Unsubscribe: