ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: from-ruby-lang@serversnab.ru
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96790] [Ruby master Feature#11747] "bury" feature, similar to 'dig' but opposite
Date: Sat, 11 Jan 2020 20:38:10 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-83784.20200111203809.d065f59e8f31333b@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11747.20151127201637@ruby-lang.org

Issue #11747 has been updated by cvss (Kirill Vechera).


A proposal to specify the path for `bury` with classes as values of a hash arg:

```
{}.bury(users: Array, 0: Hash, name: Hash, something: 'Value') # {user: [{name: {something: 'Value'}]}

----------------------------------------
Feature #11747: "bury" feature, similar to 'dig' but opposite 
https://bugs.ruby-lang.org/issues/11747#change-83784

* Author: dam13n (damien sutevski)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
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/

  parent reply	other threads:[~2020-01-11 20:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11747.20151127201637@ruby-lang.org>
2015-11-27 20:16 ` [ruby-core:71709] [Ruby trunk - Feature #11747] [Open] "bury" feature, similar to 'dig' but opposite dameyawn
2015-11-27 22:33 ` [ruby-core:71714] [Ruby trunk - Feature #11747] [Feedback] " nobu
2015-11-28 14:38 ` [ruby-core:71720] [Ruby trunk - Feature #11747] " sawadatsuyoshi
2015-12-02 23:36 ` [ruby-core:71805] " dameyawn
2015-12-07  7:29 ` [ruby-core:71885] [Ruby trunk - Feature #11747] [Rejected] " matz
2018-05-17 16:42 ` [ruby-core:87143] [Ruby trunk Feature#11747] " brianhingyenkung
2019-07-14  2:52 ` [ruby-core:93743] [Ruby master " briank
2020-01-11 20:38 ` from-ruby-lang [this message]
2020-01-11 20:44 ` [ruby-core:96791] " from-ruby-lang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-83784.20200111203809.d065f59e8f31333b@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).