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 28C8619E0036 for ; Thu, 10 Dec 2015 20:55:14 +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 79E8BB5D911 for ; Thu, 10 Dec 2015 21:26:59 +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 14F8F18CC7B5 for ; Thu, 10 Dec 2015 21:26:59 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B4C011204C0; Thu, 10 Dec 2015 21:26:57 +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 E2071120498 for ; Thu, 10 Dec 2015 21:26:52 +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=ZmAmoaYeGCxggZkiQktNsOccZD8=; b=dNtdFWnLUj1Esl0Xwd N2sBXaxjxI1/3D5qHk7mXZCt3Pg42bvdvBAA6rOpzlZWQlYmBMW/Ubl1T9DUKpT6 iyx3Bu52vqpef0V7zH4jmSSCF8RK1lsZguqyK0kACFOhgccnnJ7y7H5lntqQb0Ed EoUpV7/fR/YfArAXi8wRSP3KA= Received: by filter0552p1mdw1.sendgrid.net with SMTP id filter0552p1mdw1.24080.56696F8736 2015-12-10 12:26:47.59409675 +0000 UTC Received: from herokuapp.com (ec2-54-161-133-233.compute-1.amazonaws.com [54.161.133.233]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id Sb43OCpXR0qnzeP6uYDhCQ for ; Thu, 10 Dec 2015 12:26:47.839 +0000 (UTC) Date: Thu, 10 Dec 2015 12:26:47 +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: 46733 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7820lzKPXqDO0g/8++Z9LvpJlZbGr/dIK6zW tqiYBIFN33zjhTUpUWRJmIGd4NbLZuGuD7xiB/StAmZ6y9oWQdQRWKNBYOH0OmVmS2U9fRUJqL+Bl0 ZxO7duArny3XVER19Uill9UQyeb7NoQvmPL+ X-ML-Name: ruby-core X-Mail-Count: 72030 Subject: [ruby-core:72030] [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 made a gem for this. [gem assign](https://github.com/danielpclark/assign) I figure Kernel#assign is the best method name for this and the object it returns is an Assignable object. ---------------------------------------- Feature #11690: Update Hash during multiple assignment https://bugs.ruby-lang.org/issues/11690#change-55442 * 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/