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.8 required=3.0 tests=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=no 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 01E8D1F609 for ; Wed, 28 Nov 2018 12:20:05 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id CFA60121460; Wed, 28 Nov 2018 21:20:03 +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 2E24612145E for ; Wed, 28 Nov 2018 21:20:00 +0900 (JST) Received: by filter0044p3iad2.sendgrid.net with SMTP id filter0044p3iad2-23655-5BFE87ED-29 2018-11-28 12:19:57.468257546 +0000 UTC m=+1095021.902658794 Received: from herokuapp.com (ec2-54-166-50-162.compute-1.amazonaws.com [54.166.50.162]) by ismtpd0009p1iad2.sendgrid.net (SG) with ESMTP id lBXsxSu9TJSJWoE9izOxqg for ; Wed, 28 Nov 2018 12:19:57.403 +0000 (UTC) Date: Wed, 28 Nov 2018 12:19:58 +0000 (UTC) From: sawadatsuyoshi@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 65514 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15352 X-Redmine-Issue-Author: gfx X-Redmine-Sender: sawa 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS6zEvoLnhPGPPRpziNFPWuDMyalqcKOaT49b9 jdNMECGz3bofIhSyDuUOsaT76/xs3+EmaBzFRzEBAlokvzEoAREuxWYicJ8sNOZ576eVJTMKDJaK/Q vta8DlyP+YwUfYNBs5adUWECAokVVvKYM7rxmh3AZP0qLZOiIWoTYJJmJg== X-ML-Name: ruby-core X-Mail-Count: 90118 Subject: [ruby-core:90118] [Ruby trunk Feature#15352] Mandatory block parameters 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 #15352 has been updated by sawa (Tsuyoshi Sawada). I don't find this feature useful. If you wanted to raise an error when no block is given, all you have to do is call `yield` within the method body, which will not be an extra code if you are going to use the block somewhere in the method body. ```ruby def foo yield end foo # >> `foo': no block given (yield) (LocalJumpError) ``` And in case you want to return an error with a different message, then that is when you want to implement your custom validation clause in your code like the ones found in the examples that you have searched. ---------------------------------------- Feature #15352: Mandatory block parameters https://bugs.ruby-lang.org/issues/15352#change-75239 * Author: gfx (Goro FUJI) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- There are too many block parameter assertions (it's kind of idioms: [`raise NoBlockGiven unless glock_given?`](https://github.com/search?q=raise+NoBlockGiven+unless+block_given&type=Code)). It's very useful if there's a syntax to declare mandatory block parameters, such as: ```ruby def foo(&!block) block.call end foo() # raises ArgumentError "in `foo`: no block given" ``` -- https://bugs.ruby-lang.org/