Issue #15526 has been updated by shevegen (Robert A. Heiler).


> What do you guys think?

Ultimately you only have to convince matz, so the rest is just people giving opinions. :)

> Not exactly what you are describing, but, funny enough, there is a way!

    config.then { |host:, port:|

Admit it, you only wanted to use **.then**. ;)

To the original suggestion:

    { host, port } = config

Personally I am not a huge fan of the syntax proposal simply due to
the {} part. My brain tends to associate this as a Hash, so I get confused
when the {} is on the left side. {} already has quite some meanings, e. g.
do/end. I would rather prefer to keep any meaning of {} smaller rather
than expand on it.

Syntax aside, I am not sure I like the proposal as such either, but I don't
care that much really. My opinion is slightly against it but it's not that
strong.

> I know Ruby has Hash#values_at, but I think this way it's more readable
> and understandable

I prefer .values_at since I like object.method notation in general, unless
there is a significantly shorter and readable way that does not cause
that much confusion. But I think this is difficult to agree because what 
may be readable or easy to understand for one person, may be difficult
to understand for someone else.

Actually, although I myself still am not using yield_self/then, I'd rather
prefer the variant shown by Victor, rather than the { } variant on the 
left hand side, but that may be just my own personal opinion.

If you feel strongly about your proposal you could consider adding your
proposal to any upcoming developer meeting.


----------------------------------------
Feature #15526: New way to destruct an object hash
https://bugs.ruby-lang.org/issues/15526#change-76252

* Author: alissonbruno.sa (Alisson  Santos)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
JavaScript has a nice a neat way to destruct objects.

~~~ javascript
const person = { name: "John Doe", age: 33 };
const { name, age } =  person;
~~~

Erlang has a similar way to destruct a tuple:
~~~ erlang
Person = {"John Doe", 33}
{Name, Age} = Person
~~~

I think it's very handy and would be nice if we have something similar in Ruby.

~~~ ruby
config = { host: 'localhost', port: 3000 } 
{ host, port } = config
~~~

I know Ruby has Hash#values_at, but I think this way it's more readable and understandable

What do you guys think?




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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>