[#106341] [Ruby master Bug#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" } — dorianmariefr <noreply@...>
Issue #18369 has been reported by dorianmariefr (Dorian Mari辿).
14 messages
2021/11/30
[#106351] [Ruby master Bug#18371] Release branches (release information in general) — "tenderlovemaking (Aaron Patterson)" <noreply@...>
Issue #18371 has been reported by tenderlovemaking (Aaron Patterson).
7 messages
2021/11/30
[ruby-core:106161] [Ruby master Feature#11256] anonymous block forwarding
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2021-11-18 22:12:06 UTC
List:
ruby-core #106161
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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>