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 037CE19C022C for ; Tue, 17 Nov 2015 06:00:57 +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 6CED0B5D897 for ; Tue, 17 Nov 2015 06:31:23 +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 8194A18CC7B1 for ; Tue, 17 Nov 2015 06:31:23 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E98A0120446; Tue, 17 Nov 2015 06:31:18 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from mail-qg0-f51.google.com (mail-qg0-f51.google.com [209.85.192.51]) by neon.ruby-lang.org (Postfix) with ESMTPS id D393712040F for ; Tue, 17 Nov 2015 06:31:12 +0900 (JST) Received: by qgea14 with SMTP id a14so59689042qge.0 for ; Mon, 16 Nov 2015 13:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type; bh=X7TgwDy7l4WgPJzZXmp/vpsn0R+SKg5SzkDyoUv2x1w=; b=IfVFtcFDozFvQPl6O9QMIiqH58Pf/7wHXGM+Q/XelOIL4v4zHctwvFbW+k3juQ4SV5 hylq7v8QYhUQc8Tv6ngC9DuzKZrOkpJsw0LIPXVfqnVCLXL1ZvJglU2xj0ILKLV8gBqe ffgn6TbPfamqITWj+aeSrxadxaKc77bkk7PukdSvicrI3eEPmauCKMbzVtCXbuvP/6Rx dawPZzKcgkTZavxSJXVAelMewdYjE8r/ISVdK7BN0+FIEvb5J9VWMPbHc65kTWBMmmC1 bTTUoYJ30iFMPX5phs/pbu2CMaYmAv8HZTowpOPEMvaegsh4cNwIDLGMYpAwFLBDrUxF K4fg== MIME-Version: 1.0 X-Received: by 10.140.106.166 with SMTP id e35mr38129292qgf.17.1447709469686; Mon, 16 Nov 2015 13:31:09 -0800 (PST) Received: by 10.55.184.129 with HTTP; Mon, 16 Nov 2015 13:31:09 -0800 (PST) Received: by 10.55.184.129 with HTTP; Mon, 16 Nov 2015 13:31:09 -0800 (PST) In-Reply-To: References: Date: Tue, 17 Nov 2015 07:31:09 +1000 X-Google-Sender-Auth: BQBgoyXwPcq_bWMRIBQRdtASczw Message-ID: From: Matthew Kerwin To: Ruby developers Content-Type: multipart/alternative; boundary=001a113a67acadc1d90524af2075 X-ML-Name: ruby-core X-Mail-Count: 71508 Subject: [ruby-core:71508] Re: [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" --001a113a67acadc1d90524af2075 Content-Type: text/plain; charset=UTF-8 On 17/11/2015 12:18 AM, <6ftdan@gmail.com> wrote: > > 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] > ~~~ > Good point. I won't suggest anything to do with hash-splatting ** ;) > 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 > ~~~ > It's still very strange to think of 'update' as a property of a hash object. Without some kind of new syntactic construct, with its own clear semantics, this seems like a hack and doesn't feel right in the core (to me; others may disagree.) --001a113a67acadc1d90524af2075 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On 17/11/2015 12:18 AM, <6ftdan@gmai= l.com> wrote:
>
> Issue #11690 has been updated by Daniel P. Clark.
>
>
> I'm not sure the opts[*] is a good idea.=C2=A0 You have have curre= nt splat behavior with multiple assignment.
>
> ~~~ruby
> a, *, c =3D [1,2,3,4,5]
> a
> # =3D> 1
> c
> # =3D> 5
> ~~~
>
> And the opts[*] is unclear about what it is and what it expects.=C2=A0= It could be a Proc.
>
> ~~~ruby
> prc =3D proc {|b,c,d| b+c+d }
> # if [*] were implemented
> a, prc[*], c =3D [1,2,3,4,5]
> ~~~
>

Good point. I won't suggest anything to do with hash-spl= atting **=C2=A0 ;)

> As far as I know **Hash** is the only core object with = an **update** method.=C2=A0 And in other cases where **update** is used, su= ch as in Rails' ActiveRecord, a Hash is the expected input.=C2=A0 So wh= en the **update** method is called it is generally understood to be expecti= ng a **Hash** object.
>
> Implementing [*] would be much more work that simply implementing `Has= h#update=3D`
>
> I was thinking about suggesting `Hash#merge!=3D` as well but Ruby synt= ax does not allow the equals sign after and exclamation point.=C2=A0 So I h= ave chosen to only suggest `Hash#update=3D`
>
> ~~~ruby
> class Hash
> =C2=A0 def update=3D(h)
> =C2=A0 =C2=A0 update(h)
> =C2=A0 end
> end
> ~~~
>

It's still very strange to think of 'update' as = a property of a hash object. Without some kind of new syntactic construct, = with its own clear semantics, this seems like a hack and doesn't feel r= ight in the core (to me; others may disagree.)

--001a113a67acadc1d90524af2075--