Actions
Feature #10883
closedPassing a block to itself
Feature #10883:
Passing a block to itself
Status:
Closed
Assignee:
-
Target version:
-
Description
In the discussion of itself
some people proposed that passing a block to itself could return the value of the block:
It would be very usefull in method chains
Updated by phluid61 (Matthew Kerwin) over 11 years ago
Not exactly a duplicate, but also see the discussion at #6373
Updated by recursive-madman (Recursive Madman) over 11 years ago
Updated by shan (Shannon Skipper) over 11 years ago
I think having a block form of #itself would be great. Here's a highly contrived example:
Instead of nested parens, the following reads left to right:
It also allows a variety of other niceties:
["Hello", "Word"].itself { |greeting, subject| "#{greeting}... #{subject}!!" }
#=> "Hello... Word!!"
So like #tap except it returns itself instead of just tapping in.
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
Why itself doesn't return itself?
It seems very confusing.
Updated by baweaver (Brandon Weaver) over 11 years ago
Updated by avit (Andrew Vit) over 10 years ago
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Status changed from Open to Closed
Actions