[ruby-core:113707] [Ruby master Feature#19699] Need a way to store values like dig

Issue #19699 has been reported by edufcarvalho (Eduardo Carvalho). ---------------------------------------- Feature #19699: Need a way to store values like dig https://bugs.ruby-lang.org/issues/19699 * Author: edufcarvalho (Eduardo Carvalho) * Status: Open * Priority: Normal ---------------------------------------- Currently, there is no way to perform a `.store` operation on nested hashes in Ruby as there is for accessing them using `.dig`, so I would like to propose something like: Hash#dig_store(*args, **kwargs, arg = nil), which fills the value at *args with **kwargs if the value at *args is a hash, or with arg if the value is something else. Here are some examples: ```ruby a = {} a.dig_store(:a, :b, :c, :d, 10) => {:a=>{:b=>{:c=>{:d=>10}}}} ``` ```ruby a = {} a.dig_store(:a, :b, :c, :d, a: 10, b: 20, c: 30) => {:a=>{:b=>{:c=>{:d=>{:a=>10, :b=>20, :c=>30}}}}} ``` ```ruby a = {a: {b: {c: "test"}}} a.dig_store(:a, :b, :c, "123") => {:a=>{:b=>{:c=>"123"}}} ``` ```ruby a = {a: {b: {c: {}}} a.dig_store(:a, :b, :c, a: 10, b: 20) => {:a=>{:b=>{:c=>{:a=>10, :b=>20}}}} ``` I'm not that skilled on Ruby (actually a Junior developer), but i'm looking forward to implementing it if the core team approves it -- https://bugs.ruby-lang.org/

Issue #19699 has been updated by edufcarvalho (Eduardo Carvalho). Currently, there is no way to perform a `.store` operation on nested hashes in Ruby as there is for accessing them using `.dig`, so I would like to propose something like: Hash#dig_store(*args, **kwargs), which fills the value at *args with **kwargs if the value at *args is a hash, or with the args.last if the value is something else. Here are some examples: ```ruby a = {} a.dig_store(:a, :b, :c, :d, 10) => {:a=>{:b=>{:c=>{:d=>10}}}} ``` ```ruby a = {} a.dig_store(:a, :b, :c, :d, a: 10, b: 20, c: 30) => {:a=>{:b=>{:c=>{:d=>{:a=>10, :b=>20, :c=>30}}}}} ``` ```ruby a = {a: {b: {c: "test"}}} a.dig_store(:a, :b, :c, "123") => {:a=>{:b=>{:c=>"123"}}} ``` ```ruby a = {a: {b: {c: {}}} a.dig_store(:a, :b, :c, a: 10, b: 20) => {:a=>{:b=>{:c=>{:a=>10, :b=>20}}}} ``` I'm not that skilled on Ruby (actually a Junior developer), but i'm looking forward to implementing it if the core team approves ---------------------------------------- Feature #19699: Need a way to store values like dig https://bugs.ruby-lang.org/issues/19699#change-103353 * Author: edufcarvalho (Eduardo Carvalho) * Status: Open * Priority: Normal ---------------------------------------- Currently, there is no way to perform a `.store` operation on nested hashes in Ruby as there is for accessing them using `.dig`, so I would like to propose something like: Hash#dig_store(*args, **kwargs, arg = nil), which fills the value at *args with **kwargs if the value at *args is a hash, or with arg if the value is something else. Here are some examples: ```ruby a = {} a.dig_store(:a, :b, :c, :d, 10) => {:a=>{:b=>{:c=>{:d=>10}}}} ``` ```ruby a = {} a.dig_store(:a, :b, :c, :d, a: 10, b: 20, c: 30) => {:a=>{:b=>{:c=>{:d=>{:a=>10, :b=>20, :c=>30}}}}} ``` ```ruby a = {a: {b: {c: "test"}}} a.dig_store(:a, :b, :c, "123") => {:a=>{:b=>{:c=>"123"}}} ``` ```ruby a = {a: {b: {c: {}}} a.dig_store(:a, :b, :c, a: 10, b: 20) => {:a=>{:b=>{:c=>{:a=>10, :b=>20}}}} ``` I'm not that skilled on Ruby (actually a Junior developer), but i'm looking forward to implementing it if the core team approves it -- https://bugs.ruby-lang.org/

Issue #19699 has been updated by byroot (Jean Boussier). Status changed from Open to Closed I believe this is a duplicate of [Feature #14564], [Feature #13179] and [Feature #11747]. This was previously rejected by Matz because it was lacking a use case and lacking a proper name. I'm somewhat sympathetic to this feature request, but I don't think it really move the needle in term of proposal, so I'll close it as duplicate. Thanks though. ---------------------------------------- Feature #19699: Need a way to store values like dig https://bugs.ruby-lang.org/issues/19699#change-103360 * Author: edufcarvalho (Eduardo Carvalho) * Status: Closed * Priority: Normal ---------------------------------------- Currently, there is no way to perform a `.store` operation on nested hashes in Ruby as there is for accessing them using `.dig`, so I would like to propose something like: Hash#dig_store(*args, **kwargs, arg = nil), which fills the value at *args with **kwargs if the value at *args is a hash, or with arg if the value is something else. Here are some examples: ```ruby a = {} a.dig_store(:a, :b, :c, :d, 10) => {:a=>{:b=>{:c=>{:d=>10}}}} ``` ```ruby a = {} a.dig_store(:a, :b, :c, :d, a: 10, b: 20, c: 30) => {:a=>{:b=>{:c=>{:d=>{:a=>10, :b=>20, :c=>30}}}}} ``` ```ruby a = {a: {b: {c: "test"}}} a.dig_store(:a, :b, :c, "123") => {:a=>{:b=>{:c=>"123"}}} ``` ```ruby a = {a: {b: {c: {}}} a.dig_store(:a, :b, :c, a: 10, b: 20) => {:a=>{:b=>{:c=>{:a=>10, :b=>20}}}} ``` I'm not that skilled on Ruby (actually a Junior developer), but i'm looking forward to implementing it if the core team approves it -- https://bugs.ruby-lang.org/
participants (2)
-
byroot (Jean Boussier)
-
edufcarvalho (Eduardo Carvalho)