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 3A87F19C022C for ; Mon, 16 Nov 2015 22:47:00 +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 E91FDB5D83D for ; Mon, 16 Nov 2015 23:17:22 +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 6403E18CC7D1 for ; Mon, 16 Nov 2015 23:17:23 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8CC09120411; Mon, 16 Nov 2015 23:17:21 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 7E47A120400 for ; Mon, 16 Nov 2015 23:17:17 +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=2dHs8qKJueem+xBj7aZeLW1u4y4=; b=rj2T5I8CXTWgzDTonM ExhO3pmYbvOaxjf+aIDJaedMaZpx7RS6yPaZ9bOnn5ZNO9M+s3CcFih6dGUBmxml Of41WdzrJPvVI4JwnNumneWWEuoj2ul/OohZtMMcVyUgJSXy4etdinLAJUec8X8v /+apvj4nkMY4UiOduaYbJavuo= Received: by filter0504p1mdw1.sendgrid.net with SMTP id filter0504p1mdw1.8143.5649E56669 2015-11-16 14:17:10.867924739 +0000 UTC Received: from herokuapp.com (ec2-54-82-47-121.compute-1.amazonaws.com [54.82.47.121]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id iRKjxOvJR4eK33PMAzZm9g for ; Mon, 16 Nov 2015 14:17:10.759 +0000 (UTC) Date: Mon, 16 Nov 2015 14:17:10 +0000 From: 6ftdan@gmail.com 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: 46158 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11690 X-Redmine-Issue-Author: danielpclark X-Redmine-Sender: danielpclark 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4g8jU0Km0FOQ8G0pTAKWxEZGB8Mj5DXOlT9D 5yQI6iErr4gJkpsk5Nw2JydhBpomLlxp8Tz93ooP1mFDCcHo2AEfpHBSShgv/pqkrEueVi/cwiuQeA EfIvHrLH8sFzU/2gDsHDxgRrizECqxcM4izi X-ML-Name: ruby-core X-Mail-Count: 71507 Subject: [ruby-core:71507] [Ruby trunk - Feature #11690] Update Hash during multiple assignment 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 #11690 has been updated by Daniel P. Clark. I'm not sure the opts[*] is a good idea. You have have current splat behavior with multiple assignment. ~~~ruby a, *, c = [1,2,3,4,5] a # => 1 c # => 5 ~~~ And the opts[*] is unclear about what it is and what it expects. It could be a Proc. ~~~ruby prc = proc {|b,c,d| b+c+d } # if [*] were implemented a, prc[*], c = [1,2,3,4,5] ~~~ As far as I know **Hash** is the only core object with an **update** method. And in other cases where **update** is used, such as in Rails' ActiveRecord, a Hash is the expected input. So when the **update** method is called it is generally understood to be expecting a **Hash** object. Implementing [*] would be much more work that simply implementing `Hash#update=` I was thinking about suggesting `Hash#merge!=` as well but Ruby syntax does not allow the equals sign after and exclamation point. So I have chosen to only suggest `Hash#update=` ~~~ruby class Hash def update=(h) update(h) end end ~~~ ---------------------------------------- Feature #11690: Update Hash during multiple assignment https://bugs.ruby-lang.org/issues/11690#change-54879 * Author: Daniel P. Clark * Status: Open * Priority: Normal * Assignee: ---------------------------------------- Given that we can assign multiple variables at once ~~~ruby a,b,c = 1,2,3 ~~~ It would be nice to be able to update a Hash during multiple assignment rather than replacing it. Currently ~~~ruby x = {a: 1, b: 2} x, y ,z = {c: 3}, 6, 7 x # => {c: 3} ~~~ What I propose is adding `Hash#update=` to permit updating during multiple assignment. ~~~ruby class Hash def update=(h) update(h) end end x = {a: 1, b: 2} x.update, y ,z = {c: 3}, 6, 7 x # => {a: 1, b: 2, c: 3} ~~~ This would be most useful in scenarios where a method or proc return multiple values. When the method returns the values we don't normally know the key outside where the hash assignment is. ~~~ruby example = proc { [{:hi => :hello}, 5] } hash = {} # Currently in Ruby with an Unknown key multiple assignment isn't an option hash[????], current = example.call # We currently have to two step it result, current = example.call hash.update(result) ~~~ But with `Hash#update=` we don't have to know the key. -- https://bugs.ruby-lang.org/