ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: sawadatsuyoshi@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:90118] [Ruby trunk Feature#15352] Mandatory block parameters
Date: Wed, 28 Nov 2018 12:19:58 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-75239.20181128121956.c61852454bd67ba2@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15352.20181128012911@ruby-lang.org

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/

      parent reply	other threads:[~2018-11-28 12:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15352.20181128012911@ruby-lang.org>
2018-11-28  1:29 ` [ruby-core:90105] [Ruby trunk Feature#15352] Mandatory block parameters gfuji
2018-11-28 11:05 ` [ruby-core:90116] " shevegen
2018-11-28 12:19 ` sawadatsuyoshi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-75239.20181128121956.c61852454bd67ba2@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).