From: "jeremyevans0 (Jeremy Evans)" Date: 2021-11-18T22:12:06+00:00 Subject: [ruby-core:106161] [Ruby master Feature#11256] anonymous block forwarding Issue #11256 has been updated by jeremyevans0 (Jeremy Evans). bughit (bug hit) wrote in #note-18: > mame (Yusuke Endoh) wrote in #note-16: > > @matz accepted this, but said that the formal argument must explicitly receive a anonymous block parameter, i.e. > > > > ``` > > def foo(&) = bar(&) # OK > > def foo = bar(&) # NG > > ``` > > > > In the future, matz wants to make it more explicit whether a method accepts a block or not. > > > > Where is the naked ampersand in def foo(&) described? > > Don't see it here: https://docs.ruby-lang.org/en/master/doc/syntax/methods_rdoc.html This hasn't been committed yet, so you wouldn't see it on the website yet. The pull request already includes updates to the documentation: https://github.com/ruby/ruby/pull/5051/files#diff-d2caf8d6be0d2ccf90ff06a49bd1b4e4738588b4d5332954d57640e6fce0fd88 > Does it mean the block is required? No, just as `&block` doesn't mean the block is required. > What is the reason for the restriction? > > The block may or may not be passed to `def foo`, so what is wrong with forwarding it or its absence with `&`? It reduces the utility of this feature, for what gain? `In the future, matz wants to make it more explicit whether a method accepts a block or not.` I assume that means that we could see future changes in Ruby that better align with requiring `&` as a parameter, even if currently it seems reasonable that it would not be required. In terms of gain currently, if `&` is required, the code to implement the feature is much simpler. Ruby is already very complex internally. If we can reduce the amount of complexity added, that is a good reason. ---------------------------------------- Feature #11256: anonymous block forwarding https://bugs.ruby-lang.org/issues/11256#change-94763 * Author: bughit (bug hit) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- since capturing a block into a proc is slow: foo(&block) and creating chains of blocks is kind of ugly and ultimately also inefficient: foo{yield} why not allow block forwarding without capturing: foo(&) foo(1, 2, &) -- https://bugs.ruby-lang.org/ Unsubscribe: