From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id E76D71F46C for ; Sat, 11 Jan 2020 20:38:32 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A059E120A0B; Sun, 12 Jan 2020 05:38:13 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id A0C2F1209FB for ; Sun, 12 Jan 2020 05:38:10 +0900 (JST) Received: by filterdrecv-p3iad2-57f487d66-lm2v9 with SMTP id filterdrecv-p3iad2-57f487d66-lm2v9-17-5E1A3232-1D 2020-01-11 20:38:10.321026443 +0000 UTC m=+2231491.104670987 Received: from herokuapp.com (unknown [54.224.129.129]) by ismtpd0019p1iad2.sendgrid.net (SG) with ESMTP id mLSvAv6yStCUuuPWM8uklQ for ; Sat, 11 Jan 2020 20:38:10.197 +0000 (UTC) Date: Sat, 11 Jan 2020 20:38:10 +0000 (UTC) From: from-ruby-lang@serversnab.ru Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72453 X-Redmine-Project: ruby-master X-Redmine-Issue-Id: 11747 X-Redmine-Issue-Author: dam13n X-Redmine-Issue-Assignee: matz X-Redmine-Sender: cvss X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?dpuTrO8BI1nuZccY7HwSQsjUKStik437a7ABWmzEg2634dLkuJv4nHhdlimJ0s?= =?us-ascii?Q?1webdvpvAXkDhU0=2FGR3+7ZFpaPc33jEQNn0yY=2FL?= =?us-ascii?Q?h3m9QP0gGmMorRARbD6p=2FrFXaEq6txEQkfc+LCh?= =?us-ascii?Q?rDRyAxOtngCzrLb029QwdxHk6Rd237GwKiEuGdE?= =?us-ascii?Q?S14s5b1IsAra6=2Fbn7fqCmhUviseVDUcedEH9tsQ?= =?us-ascii?Q?Ba=2FSCIMF1be0mQv9s=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96790 Subject: [ruby-core:96790] [Ruby master Feature#11747] "bury" feature, similar to 'dig' but opposite X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/