From: shyouhei@... Date: 2017-12-21T07:27:21+00:00 Subject: [ruby-core:84386] [Ruby trunk Feature#12318][Closed] Returning the evaluated value of a block Issue #12318 has been updated by shyouhei (Shyouhei Urabe). Status changed from Open to Closed avit (Andrew Vit) wrote: > This is now implemented as `yield_self` > > Close please? Yes. Closing. ---------------------------------------- Feature #12318: Returning the evaluated value of a block https://bugs.ruby-lang.org/issues/12318#change-68576 * Author: sawa (Tsuyoshi Sawada) * Status: Closed * Priority: Normal * Assignee: * Target version: ---------------------------------------- I often achieve an element using an iterator with a block, and then apply the same/a similar block to the element I get. Examples are: ~~~ruby [7, 8, 9] .max_by{|e| e % 3} .tap{|e| break e % 3} # => 2 ["foo", "bar", "baz"] .find{|e| e[/(.)\1/]} .tap{|e| break e[/(.)\1/]} # => "oo" ~~~ I would like a method on `Enumerator` that returns the result of the block rather than the original element in the iterator. Not sure about the name, but if I call it `and_return` temporary, it should look like: ~~~ruby [7, 8, 9] .max_by.and_return{|e| e % 3} # => 2 ["foo", "bar", "baz"] .find.and_return{|e| e[/(.)\1/]} # => "oo" ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: