From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 1268119C0421 for ; Sat, 28 Nov 2015 07:02:15 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 358BBB5D8D8 for ; Sat, 28 Nov 2015 07:33:27 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 49E2C18CC7B6 for ; Sat, 28 Nov 2015 07:33:27 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3021912056B; Sat, 28 Nov 2015 07:33:25 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2C29D12051F for ; Sat, 28 Nov 2015 07:33:21 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=0SAXxcGCwXLAV9hFNMbKpTawDhU=; b=WklmNHSrkTIUa11Xrv F8V3eJv6r2pQw6oTrDHHGdHHHQyUuc75HifP7pDVgNZbfI23+sKAcUPJHc7SA2Ev 2PmTmFlTTjnmLRsR3IhntyPJtY01KUfYW+RW4sOj/wTm6p5UHQOe8s3Q1fx0sx2F 5/772l5n46P69v3B82x+pMcHc= Received: by filter0621p1mdw1.sendgrid.net with SMTP id filter0621p1mdw1.17008.5658DA2D6 2015-11-27 22:33:17.137986464 +0000 UTC Received: from herokuapp.com (ec2-54-90-106-190.compute-1.amazonaws.com [54.90.106.190]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id GbABQjPsTyS7esab52Fweg for ; Fri, 27 Nov 2015 22:33:17.388 +0000 (UTC) Date: Fri, 27 Nov 2015 22:33:17 +0000 From: nobu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46397 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11747 X-Redmine-Issue-Author: dam13n X-Redmine-Issue-Assignee: matz X-Redmine-Sender: nobu 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: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5ELQ1p3CXXXxf7G7VCiiDBHMln7COhDfUHQ6 v3LPBMGAJGz3X6Vt9sU9m6nrQpWthyfY+7p7N5bsVdOlemA2XAUZ27+Kd7GnwmXPj4B7cynlp0Au5V Om1vVfNMxXcH1WGwwCf4hXAaemfi0E8F46nn X-ML-Name: ruby-core X-Mail-Count: 71714 Subject: [ruby-core:71714] [Ruby trunk - Feature #11747] [Feedback] "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: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11747 has been updated by Nobuyoshi Nakada. Description updated Status changed from Open to Feedback How can it know what should be created, hash, array, or struct? ---------------------------------------- Feature #11747: "bury" feature, similar to 'dig' but opposite https://bugs.ruby-lang.org/issues/11747#change-55120 * 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/