From 4adb012926f8bd6011168327d8832cf19976de40 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 18 Nov 2021 12:44:19 -0800 Subject: 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 --- doc/syntax/methods.rdoc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'doc') 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 yield without an explicit +or send it to another method, using yield without an explicit block parameter is preferred. This method is equivalent to the first method in this section: -- cgit v1.2.3