From: knu@... Date: 2019-03-11T09:54:34+00:00 Subject: [ruby-core:91771] [Ruby trunk Feature#15618] Implement Enumerator::Yielder#to_proc Issue #15618 has been updated by knu (Akinori MUSHA). Status changed from Open to Closed Merged with [Feature #15618]. ---------------------------------------- Feature #15618: Implement Enumerator::Yielder#to_proc https://bugs.ruby-lang.org/issues/15618#change-77048 * Author: knu (Akinori MUSHA) * Status: Closed * Priority: Normal * Assignee: * Target version: ---------------------------------------- When writing an Enumerator block, you often want to delegate iteration to another method like this: ```ruby enum = Enumerator.new { |y| Dir.glob("*.rb") { |file| File.open(file) { |f| f.each_line { |line| y << line } } } } ``` I think this is such a common pattern, but the `{ |var| y << var }` part looks redundant compared to a normal iterator method being able to delegate to another method as simply as follows: ``` def each(&block) @children.each(&block) end ``` So, I propose adding #to_proc to Yielder so you can directly pass a yielder object to another method as a block argument. ```ruby enum = Enumerator.new { |y| Dir.glob("*.rb") { |file| File.open(file) { |f| f.each_line(&y) } } } ``` Yielder is all about yielding, so I think it's pretty obvious what it means. ---Files-------------------------------- 0001-Implement-Enumerator-Yielder-to_proc.patch (3.21 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: