* [ruby-core:79381] [Ruby trunk Bug#13179] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
@ 2017-02-01 18:46 ` bettisworth
2017-02-02 6:50 ` [ruby-core:79389] [Ruby trunk Feature#13179][Feedback] " nobu
` (6 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: bettisworth @ 2017-02-01 18:46 UTC (permalink / raw
To: ruby-core
Issue #13179 has been reported by Andy Bettisworth.
----------------------------------------
Bug #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179
* Author: Andy Bettisworth
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:79389] [Ruby trunk Feature#13179][Feedback] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
2017-02-01 18:46 ` [ruby-core:79381] [Ruby trunk Bug#13179] Deep Hash Update Method bettisworth
@ 2017-02-02 6:50 ` nobu
2017-02-03 4:22 ` [ruby-core:79401] [Ruby trunk Feature#13179] " shevegen
` (5 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: nobu @ 2017-02-02 6:50 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by Nobuyoshi Nakada.
Tracker changed from Bug to Feature
Status changed from Open to Feedback
`dig` is not only for `Hash` but also for `Array`, `Struct`, and `OpenStruct`.
What objects would you expect as intermediate containers if not present?
Regarding the name, `bury` occurred to me.
`Hash#dig=` might fit if `obj.method(arg,...) = val` syntax were possible.
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-62816
* Author: Andy Bettisworth
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:79401] [Ruby trunk Feature#13179] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
2017-02-01 18:46 ` [ruby-core:79381] [Ruby trunk Bug#13179] Deep Hash Update Method bettisworth
2017-02-02 6:50 ` [ruby-core:79389] [Ruby trunk Feature#13179][Feedback] " nobu
@ 2017-02-03 4:22 ` shevegen
2017-02-03 5:05 ` [ruby-core:79403] " bettisworth
` (4 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: shevegen @ 2017-02-03 4:22 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by Robert A. Heiler.
> Regarding the name, bury occurred to me.
.dig and .bury - I can already feel on Halloween the .zombies() coming up!
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-62833
* Author: Andy Bettisworth
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:79403] [Ruby trunk Feature#13179] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
` (2 preceding siblings ...)
2017-02-03 4:22 ` [ruby-core:79401] [Ruby trunk Feature#13179] " shevegen
@ 2017-02-03 5:05 ` bettisworth
2017-03-02 4:56 ` [ruby-core:79856] " shyouhei
` (3 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: bettisworth @ 2017-02-03 5:05 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by Andy Bettisworth.
Any method name four or less characters long is a big win. Using bury would be much nicer than my current update_deep_hash calls.
I wasn't aware of dig in the other classes. I may be overlooking something but why not just use the class dig is used on as a container? Another way would be to allow setting the default container via an optional argument like when setting default values for a Hash, Array, and so on.
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-62835
* Author: Andy Bettisworth
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:79856] [Ruby trunk Feature#13179] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
` (3 preceding siblings ...)
2017-02-03 5:05 ` [ruby-core:79403] " bettisworth
@ 2017-03-02 4:56 ` shyouhei
2017-03-13 9:21 ` [ruby-core:80127] [Ruby trunk Feature#13179][Rejected] " matz
` (2 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: shyouhei @ 2017-03-02 4:56 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by Shyouhei Urabe.
This is possible in perl:
```
use strict;
use warnings;
use Data::Dumper qw(Dumper);
my %hash = qw();
$hash{q}{w}{e}{r}{t} = 'y';
warn(Dumper(\%hash));
```
From perl's POV it seems ruby lacks this feature.
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-63288
* Author: wurde _
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:80127] [Ruby trunk Feature#13179][Rejected] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
` (4 preceding siblings ...)
2017-03-02 4:56 ` [ruby-core:79856] " shyouhei
@ 2017-03-13 9:21 ` matz
2018-01-10 13:51 ` [ruby-core:84812] [Ruby trunk Feature#13179] " MarioRuizS
2019-07-14 13:29 ` [ruby-core:93759] [Ruby master " briank
7 siblings, 0 replies; 8+ messages in thread
From: matz @ 2017-03-13 9:21 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by matz (Yukihiro Matsumoto).
Status changed from Feedback to Rejected
It's no difference from #11747. You have to come up with a better name candidate and concrete use-case.
Matz.
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-63553
* Author: bettisworth (wurde _)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:84812] [Ruby trunk Feature#13179] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
` (5 preceding siblings ...)
2017-03-13 9:21 ` [ruby-core:80127] [Ruby trunk Feature#13179][Rejected] " matz
@ 2018-01-10 13:51 ` MarioRuizS
2019-07-14 13:29 ` [ruby-core:93759] [Ruby master " briank
7 siblings, 0 replies; 8+ messages in thread
From: MarioRuizS @ 2018-01-10 13:51 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by MarioRuiz (Mario Ruiz Sánchez).
bettisworth (wurde _) wrote:
> I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
>
> Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
What I am using in my code is a simple dig method... at least for the best cases is working nice:
~~~ ruby
#my_hash.bury([:accent,2,:original],"the value to set")
class Hash
def bury(where, value)
me=self
where[0..-2].each{|key|
me=me[key]
}
me[where[-1]]=value
end
end
#my_array.bury([2,1,:original],"the value to set")
class Array
def bury(where, value)
me=self
where[0..-2].each{|key|
me=me[key]
}
me[where[-1]]=value
end
end
~~~
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-69526
* Author: bettisworth (wurde _)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [ruby-core:93759] [Ruby master Feature#13179] Deep Hash Update Method
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
` (6 preceding siblings ...)
2018-01-10 13:51 ` [ruby-core:84812] [Ruby trunk Feature#13179] " MarioRuizS
@ 2019-07-14 13:29 ` briank
7 siblings, 0 replies; 8+ messages in thread
From: briank @ 2019-07-14 13:29 UTC (permalink / raw
To: ruby-core
Issue #13179 has been updated by bkatzung (Brian Katzung).
Gem XKeys, since 2014.
```
require 'xkeys'
h = {}.extend XKeys::Auto # auto Hash/Array
h[:accent, 2, :original] = "the value to set"
# {:accent=>[nil, nil, {:original=>"the value to set"}]}
h = {}.extend XKeys::Hash # Hash only
h[:accent,2,:original]='the value to set'
# {:accent=>{2=>{:original=>"the value to set"}}}
a = [].extend XKeys::Auto
a[2, 1, :original] = "the value to set"
# [nil, nil, [nil, {:original=>"the value to set"}]]
a[2, 1] # (slice 2, 1) [[nil, {:original=>"the value to set"}]]
a[2, 1, {}] # (a[2][1]) {:original=>"the value to set"}
```
----------------------------------------
Feature #13179: Deep Hash Update Method
https://bugs.ruby-lang.org/issues/13179#change-79400
* Author: bettisworth (wurde _)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I came across a scenario where I needed the ability to update a deeply nested hash (Rails i18n yaml files). This seemed like something that would exist naturally in the DSL of ruby, but I could only find dig() method which only retrieves values if they exist. 24 hours later I wrote a update_deep_hash method (I wouldn't wish this type of recursive coding on anyone else within the Ruby community).
Attached is the solution I hacked together. My question is if we can have a Hash.dig() method which reaches into a deep hash can we expand on this to include update methods of similar nature?
---Files--------------------------------
update_deep_hash.rb (2.26 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-07-14 13:29 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-13179.20170201184650@ruby-lang.org>
2017-02-01 18:46 ` [ruby-core:79381] [Ruby trunk Bug#13179] Deep Hash Update Method bettisworth
2017-02-02 6:50 ` [ruby-core:79389] [Ruby trunk Feature#13179][Feedback] " nobu
2017-02-03 4:22 ` [ruby-core:79401] [Ruby trunk Feature#13179] " shevegen
2017-02-03 5:05 ` [ruby-core:79403] " bettisworth
2017-03-02 4:56 ` [ruby-core:79856] " shyouhei
2017-03-13 9:21 ` [ruby-core:80127] [Ruby trunk Feature#13179][Rejected] " matz
2018-01-10 13:51 ` [ruby-core:84812] [Ruby trunk Feature#13179] " MarioRuizS
2019-07-14 13:29 ` [ruby-core:93759] [Ruby master " briank
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).