[#61822] Plan Developers Meeting Japan April 2014 — Zachary Scott <e@...>

I would like to request developers meeting around April 17 or 18 in this mo=

14 messages 2014/04/03
[#61825] Re: Plan Developers Meeting Japan April 2014 — Urabe Shyouhei <shyouhei@...> 2014/04/03

It's good if we have a meeting then.

[#61826] Re: Plan Developers Meeting Japan April 2014 — Zachary Scott <e@...> 2014/04/03

Regarding openssl issues, I=E2=80=99ve discussed possible meeting time with=

[#61833] Re: Plan Developers Meeting Japan April 2014 — Martin Bo煬et <martin.bosslet@...> 2014/04/03

Hi,

[ruby-core:62082] [ruby-trunk - Feature #8895] Destructuring Assignment for Hash

From: xovatdev@...
Date: 2014-04-17 23:25:13 UTC
List: ruby-core #62082
Issue #8895 has been updated by Sean Linsley.


This is what I'm imagining:

~~~
a, b, *c, d:, e:, f: 'f', **g =3D [1, 2, 3, {d: 4, e: 5}]

a =3D=3D 1
b =3D=3D 2
c =3D=3D [3]
d =3D=3D 4
e =3D=3D 5
f =3D=3D 'f'
g =3D=3D {}
~~~

Where an error would be thrown if the hash didn't have the given key, and n=
o default was provided.

----------------------------------------
Feature #8895: Destructuring Assignment for Hash
https://bugs.ruby-lang.org/issues/8895#change-46247

* Author: Jack Chen
* Status: Open
* Priority: Normal
* Assignee:=20
* Category:=20
* Target version:=20
----------------------------------------
=3Dbegin
Given Ruby already supports destructuring assignment with Array (a, b =3D [=
1, 2]), I propose destructuring assignments for Hash.

=3D=3D Basic example

  params =3D {name: "John Smith", age: 42}
  {name: name, age: age} =3D params

  # name =3D=3D "John Smith"
  # age =3D=3D 42

This would replace a common pattern of assigning hash values to local varia=
bles to work with.

=3D=3D General syntax

  { <key-expr> =3D> <variable_name>, =E2=80=A6 } =3D <object that responds =
to #[]>

  # Symbols
  { foo: bar } =3D { foo: "bar" }
  bar =3D=3D "bar"

  # Potential shorthand
  { foo } =3D { foo: "bar" }
  foo =3D=3D "bar"

=3D=3D Use cases:

  # MatchData
  { username: username, age: age } =3D "user:jsmith age:42".match(/user:(?<=
username>\w+) age:(?<age>\d+)/)
  username =3D=3D "jsmith"
  age =3D=3D "42"

=3D=3D Edge cases

  # Variable being assigned to more than once should use the last one
  { foo: var, bar: var } =3D {foo: 1, bar: 2}
  var =3D=3D 2

Thoughts?
=3Dend




--=20
https://bugs.ruby-lang.org/

In This Thread