ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:72269]  [Ruby trunk - Feature #11747] \"bury\" feature, similar to 'dig' but opposite
@ 2015-12-18  4:06 Joseph Jones
  2015-12-18 12:58 ` [ruby-core:72366] " Billy E Brand
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Jones @ 2015-12-18  4:06 UTC (permalink / raw)
  To: Ruby developers; +Cc: ruby-core

[-- Attachment #1: Type: text/plain, Size: 1962 bytes --]

Joseph Jones liked your message with Boxer. On December 2, 2015 at 16:36:12 MST, dameyawn@gmail.com wrote:Issue #11747 has been updated by damien sutevski.Tsuyoshi Sawada wrote:> > inferred from the what the user is passing (such as a symbol or string for a hash or an integer for an array)> > I don't think this is a good idea. I think it should rather depend on the class of the receiver.> > {}.bury(:users, 0, :name, 'Matz') # => {:users => {0 => {:name => "Matz"}}}> [].bury(:users, 0, :name, 'Matz') # => error> {}.bury(0, 1, 2, :foo) # => {0 => {1 => {2 => :foo}}}> [].bury(0, 1, 2, :foo) # => [[nil, [nil, nil, :foo]]]> > and similar for struct.I agree. I should clarify that I was assuming the class of the receiver (`data`) was known in my example. The inference I was talking about was that a buried `0` would imply an array position by default instead of a hash key.----------------------------------------Feature #11747: "bury" feature, similar to 'dig' but opposite https://bugs.ruby-lang.org/issues/11747#change-55211* Author: damien sutevski* Status: Feedback* Priority: Normal* Assignee: 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 thisdata[:users][0][:name]# we can do this w/o nil errorsdata.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:~~~rubydata.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! -- https://bugs.ruby-lang.org/     

[-- Attachment #2: Type: text/html, Size: 2535 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:72366] Re: [Ruby trunk - Feature #11747] \"bury\" feature, similar to 'dig' but opposite
  2015-12-18  4:06 [ruby-core:72269] [Ruby trunk - Feature #11747] \"bury\" feature, similar to 'dig' but opposite Joseph Jones
@ 2015-12-18 12:58 ` Billy E Brand
  0 siblings, 0 replies; 2+ messages in thread
From: Billy E Brand @ 2015-12-18 12:58 UTC (permalink / raw)
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 2402 bytes --]

Remove me from mail list please 

Sent from my iPhone
Billy E Brand
404-597-9615

> On Dec 17, 2015, at 23:06, Joseph Jones <joeyi5216@gmail.com> wrote:
> 
> Joseph Jones liked your message with Boxer.
> 
> 
>> On December 2, 2015 at 16:36:12 MST, dameyawn@gmail.com wrote:
>> Issue #11747 has been updated by damien sutevski.
>> 
>> 
>> Tsuyoshi Sawada wrote:
>> > > inferred from the what the user is passing (such as a symbol or string for a hash or an integer for an array)
>> > 
>> > I don't think this is a good idea. I think it should rather depend on the class of the receiver.
>> > 
>> > {}.bury(:users, 0, :name, 'Matz') # => {:users => {0 => {:name => "Matz"}}}
>> > [].bury(:users, 0, :name, 'Matz') # => error
>> > {}.bury(0, 1, 2, :foo) # => {0 => {1 => {2 => :foo}}}
>> > [].bury(0, 1, 2, :foo) # => [[nil, [nil, nil, :foo]]]
>> > 
>> > and similar for struct.
>> 
>> I agree. I should clarify that I was assuming the class of the receiver (`data`) was known in my example. The inference I was talking about was that a buried `0` would imply an array position by default instead of a hash key.
>> 
>> 
>> 
>> 
>> ----------------------------------------
>> Feature #11747: "bury" feature, similar to 'dig' but opposite 
>> https://bugs.ruby-lang.org/issues/11747#change-55211
>> 
>> * Author: damien sutevski
>> * Status: Feedback
>> * Priority: Normal
>> * Assignee: 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! 
>> 
>> 
>> 
>> -- 
>> https://bugs.ruby-lang.org/

[-- Attachment #2: Type: text/html, Size: 3037 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-18 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-18  4:06 [ruby-core:72269] [Ruby trunk - Feature #11747] \"bury\" feature, similar to 'dig' but opposite Joseph Jones
2015-12-18 12:58 ` [ruby-core:72366] " Billy E Brand

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).