From: "mame (Yusuke Endoh)" Date: 2012-03-27T03:32:11+09:00 Subject: [ruby-core:43719] [ruby-trunk - Feature #5389][Assigned] New method Enumerator#iterate Issue #5389 has been updated by mame (Yusuke Endoh). Status changed from Open to Assigned Assignee set to matz (Yukihiro Matsumoto) ---------------------------------------- Feature #5389: New method Enumerator#iterate https://bugs.ruby-lang.org/issues/5389#change-25221 Author: yimutang (Joey Zhou) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: If we want to iterate over the elements of a enumerable object with *multiple* blocks, we can use the Enumerator class. A method 'iterate' is required, we can write it in Ruby: class Enumerator def iterate yield_value = self.next return_value = yield yield_value self.feed return_value self end end Well, here is an example: array = (1..10).to_a enum = array.map! loop do enum.iterate {|n| n + 10 } enum.iterate {|n| n * 2 } enum.iterate {|n| -n } end p array # => [11, 4, -3, 14, 10, -6, 17, 16, -9, 20] We want to map an array: the 1st element use blk1, the 2nd use blk2, the 3rd use blk3... I think this Enumerator#iterate method is sometimes useful, so would you please introduce it into the language core? -- http://bugs.ruby-lang.org/