summaryrefslogtreecommitdiff
path: root/doc/syntax
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-11-18 12:44:19 -0800
committerJeremy Evans <code@jeremyevans.net>2021-11-18 14:17:57 -0800
commit4adb012926f8bd6011168327d8832cf19976de40 (patch)
tree9457020694002d0a0c07ced988a1d09c79fa74e6 /doc/syntax
parentea02b93bb95a42439631606269659dffc1981883 (diff)
Anonymous block forwarding allows a method to forward a passed
block to another method without having to provide a name for the block parameter. Implements [Feature #11256] Co-authored-by: Yusuke Endoh mame@ruby-lang.org Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5051
Diffstat (limited to 'doc/syntax')
-rw-r--r--doc/syntax/methods.rdoc9
1 files changed, 8 insertions, 1 deletions
diff --git a/doc/syntax/methods.rdoc b/doc/syntax/methods.rdoc
index e86cc2c00c..2bb350def1 100644
--- a/doc/syntax/methods.rdoc
+++ b/doc/syntax/methods.rdoc
@@ -515,8 +515,15 @@ Most frequently the block argument is used to pass a block to another method:
@items.each(&block)
end
+You are not required to give a name to the block if you will just be passing
+it to another method:
+
+ def each_item(&)
+ @items.each(&)
+ end
+
If you are only going to call the block and will not otherwise manipulate it
-or send it to another method using <code>yield</code> without an explicit
+or send it to another method, using <code>yield</code> without an explicit
block parameter is preferred. This method is equivalent to the first method
in this section: