From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.1 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id EA121211B4 for ; Fri, 11 Jan 2019 20:15:33 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id BF47E121D4A; Sat, 12 Jan 2019 05:15:30 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 535F0121546 for ; Sat, 12 Jan 2019 05:15:28 +0900 (JST) Received: by filter0013p3iad2.sendgrid.net with SMTP id filter0013p3iad2-17153-5C38F95D-5 2019-01-11 20:15:25.168710579 +0000 UTC m=+329480.612386657 Received: from herokuapp.com (ec2-54-80-22-201.compute-1.amazonaws.com [54.80.22.201]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id uC70pEzBTYS_Pp-byAvrwA for ; Fri, 11 Jan 2019 20:15:25.098 +0000 (UTC) Date: Fri, 11 Jan 2019 20:15:26 +0000 (UTC) From: shevegen@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66465 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15526 X-Redmine-Issue-Author: alissonbruno.sa X-Redmine-Sender: shevegen 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS71a19HkWdS4wGQ5e6NCMkD22mDPXRh95bPOw o04VwxRDWwyIv+ayyoHX7Y94+kYZr4LFWZQ86Abd1Twz/nPFLEZPRJ9uaIk6qmCaxGP5EpFhWdZ8uH x2Ky9/qxY5jWpTc5+1DNteyx8Dj8iuDzqWayicCyKh5WmY3CypyGtHg9wg== X-ML-Name: ruby-core X-Mail-Count: 91031 Subject: [ruby-core:91031] [Ruby trunk Feature#15526] New way to destruct an object hash 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/