From: Matthew Kerwin Date: 2015-11-17T07:31:09+10:00 Subject: [ruby-core:71508] Re: [Ruby trunk - Feature #11690] Update Hash during multiple assignment --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--