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=-2.9 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 46CA4211B4 for ; Fri, 11 Jan 2019 19:57:56 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 7A8A61216A7; Sat, 12 Jan 2019 04:57:53 +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 62E481216CB for ; Sat, 12 Jan 2019 04:57:51 +0900 (JST) Received: by filter0148p3mdw1.sendgrid.net with SMTP id filter0148p3mdw1-24005-5C38F53C-3 2019-01-11 19:57:48.07294048 +0000 UTC m=+331234.698406780 Received: from herokuapp.com (ec2-54-81-68-147.compute-1.amazonaws.com [54.81.68.147]) by ismtpd0053p1mdw1.sendgrid.net (SG) with ESMTP id 2SuYSKJ7QIaHPRwUnBoPcg for ; Fri, 11 Jan 2019 19:57:48.046 +0000 (UTC) Date: Fri, 11 Jan 2019 19:57:50 +0000 (UTC) From: zverok.offline@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66464 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15526 X-Redmine-Issue-Author: alissonbruno.sa X-Redmine-Sender: zverok 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5aXg40WlbX+L7Q+GhF4QVdwqqNihDZygQH4s 9cxy03KJz6wZwEZU2N36tdEcUVfcArkI7pmMR2VznQezPfP5m0K5AU79f7RbMBtDgzKCFgC+JSEpUQ XvMnVoRFYf4yFWlJ8hjhdW2LSivT+ZM4qQzHbwkKrb2gYv54KNW77vMKKg== X-ML-Name: ruby-core X-Mail-Count: 91030 Subject: [ruby-core:91030] [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 zverok (Victor Shepelev). Not exactly what you are describing, but, funny enough, there is a way! ```ruby config = { host: 'localhost', port: 3000 } config.then { |host:, port:| p "host=#{host}, port=#{port}" } ``` ---------------------------------------- Feature #15526: New way to destruct an object hash https://bugs.ruby-lang.org/issues/15526#change-76251 * 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/