From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_PASS,T_DKIM_INVALID, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A63C9209FD for ; Sat, 3 Jun 2017 16:39:26 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A801212075C; Sun, 4 Jun 2017 01:39:23 +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 F3FA3120755 for ; Sun, 4 Jun 2017 01:39:21 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=W4zH6MhCYTnmGSEY0Yf8T4YJVW4=; b=k+kdgq2yYtK6TmZlvf M9XUS820EaFis/0LE9/gZrrRn5J7jX1fNkX0KIArxVuz4dGOrwKL+f1/Nhd6pupQ CWV1YVZDNOlHDISqx8YiL5jtz2TizJWapgWn8arSQdcnrWh+xMpAfXD43DwNjL7a I7CrBxm/CTFUMa15xifyttE8s= Received: by filter0443p1mdw1.sendgrid.net with SMTP id filter0443p1mdw1-6691-5932E633-4B 2017-06-03 16:39:15.806286337 +0000 UTC Received: from herokuapp.com (ec2-54-167-220-180.compute-1.amazonaws.com [54.167.220.180]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id 1CkZV1hsT6m3Z2DHLRkoJw for ; Sat, 03 Jun 2017 16:39:15.742 +0000 (UTC) Date: Sat, 03 Jun 2017 16:39:15 +0000 From: shevegen@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 56594 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13630 X-Redmine-Issue-Author: khoan 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4htdWIR2TBV0SnvXPaX48+BTyq5/UfDIfgY+ G4JlmsR22Z/OTD0EXMBpuaCFxnVV726m3oFB/puh1Syg5LYUMTiiGdmfvJVzAZ4Rjh7pKWYPJEqKSu xumq6xATMAt4kJRwdcFAWQYTSICYAh4b0hY4WRJ8l9C+oPt6GOT+D70X6A== X-ML-Name: ruby-core X-Mail-Count: 81564 Subject: [ruby-core:81564] [Ruby trunk Feature#13630] :[] method should accept block in nice syntax 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 #13630 has been updated by shevegen (Robert A. Heiler). I agree. I always wondered about this too. I did not make a suggestion like this because I suspect that one reason may be a parser issue, as otherwise it would most likely have been done already. In particular for elements without any arguments like: Bam.[] { |b| puts b } Or more verbose to use your example: module Bam def self.[](bam=42) yield bam end end Bam.[] { |b| puts b } # => 42 Bam[] { |b| puts b } # => SyntaxError: (irb):14: syntax error, unexpected { arg, expecting end-of-input Only difference here between failure and success is one lonely '.'. I am not sure if it is technically possible to get rid of the '.', but if it would be possible, that would be great. The '.' visually disturbs me when I see [] ... but not at other places, it's weird. :D ---------------------------------------- Feature #13630: :[] method should accept block in nice syntax https://bugs.ruby-lang.org/issues/13630#change-65266 * Author: khoan (khoa nguyen) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- ~~~ ruby # given module Bam def self.[](bam) yield bam end end # SyntaxError: unexpected keyword_do_block Bam['bam'] do |b| puts b end # SyntaxError: unexpected { arg, expecting end-of-input Bam['bam'] { |b| puts b } # Valid but more verbose Bam.[]('bam') do |b| puts b end Bam.[]('bam') { |b| puts b } ~~~ -- https://bugs.ruby-lang.org/