From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, 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.1 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 61D461F453 for ; Mon, 22 Oct 2018 02:08:02 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 695C9120F19; Mon, 22 Oct 2018 11:07:59 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3FA10120F19 for ; Mon, 22 Oct 2018 11:07:55 +0900 (JST) Received: by filter0127p3las1.sendgrid.net with SMTP id filter0127p3las1-23690-5BCD30F8-2A 2018-10-22 02:07:52.891005095 +0000 UTC m=+276162.565258114 Received: from herokuapp.com (ec2-54-227-66-203.compute-1.amazonaws.com [54.227.66.203]) by ismtpd0021p1iad2.sendgrid.net (SG) with ESMTP id zj_yJ01gTm6-d5H3uSTdeQ for ; Mon, 22 Oct 2018 02:07:52.814 +0000 (UTC) Date: Mon, 22 Oct 2018 02:07:53 +0000 (UTC) From: lyoneil.de.sire@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 64892 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15236 X-Redmine-Issue-Author: ignatiusreza X-Redmine-Sender: ignatiusreza 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4Y2MCBlNgssAAw889YUbq2LqajiYopnp7qxY BJH3+JH3fr3sSD8ARvQ/s9+cLIa8Q5AC10I6Ico2rS6AvKFw125uin5PqkJx91HPyumIGISnJixNH4 1ePKeuygYRRLFbM+XBwzM2krObgS+ag/F+Hto86Sqnnfk8uYSSAUlUGKbQ== X-ML-Name: ruby-core X-Mail-Count: 89503 Subject: [ruby-core:89503] [Ruby trunk Feature#15236] add support for hash shorthand 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 #15236 has been updated by ignatiusreza (Ignatius Reza Lesmana). Hi guys, Thanks for the discussions! Sorry I didn't noticed that it was proposed (multiple times) before.. I tried to search, but couldn't find a hit.. The ES6 syntax that this gets inspired from is strongly becoming the standard now, partly thanks to it being enabled by default in https://www.npmjs.com/package/eslint-config-airbnb-base I found a strong the desire for this syntax especially when working on API server alongside JavaScript heavy front end, where one would need to work a lot with building hashes to be transformed into JSON string.. hence, the primary use case where i'm interested in is in building hashes as return value of method call, e.g. ~~~ ruby def respond_with(resource, options) meta = extract_meta(resource, options) etc = extract_etc(resource, options) { resource, meta, etc } end ~~~ having ~~~ ruby { resource, meta, etc } ~~~ is much more concise and cleaner compared to ~~~ ruby { resource: resource, meta: meta, etc: etc } ~~~ within this context, `{ }` is already non-optional, and the new syntax increase readability and save a lot of typing.. To address the concern in https://bugs.ruby-lang.org/issues/11105 .. I think, I agree that this shorthand syntax should only be allowed for `a`, but not for `@a`, `@@a`, or `$a` to avoid ambiguity in what key should be generated for everything else other than `a`.. ---------------------------------------- Feature #15236: add support for hash shorthand https://bugs.ruby-lang.org/issues/15236#change-74556 * Author: ignatiusreza (Ignatius Reza Lesmana) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- PR in github: https://github.com/ruby/ruby/pull/1990 inspired by javascript support for object literal shorthand notation `{ a }`, which will be expanded into `{ a: a }`.. to avoid ambiguity, this shorthand is only supported when hash is defined with `{ }` notation.. in other situation where the brackets is optional, e.g. function call, we still need to write it in full (`m(a : a)` instead of `m(a)`, or `m(a, b, c: c)` instead of `m(a, b, c)`.. -- https://bugs.ruby-lang.org/