From: "tarui (Masaya Tarui)" Date: 2012-07-05T12:04:07+09:00 Subject: [ruby-core:46191] [ruby-trunk - Feature #4633][Rejected] iterate method / extended version of for Issue #4633 has been updated by tarui (Masaya Tarui). Status changed from Assigned to Rejected Dear Jan, Sorry that I didn't reply to you sooner. Thank you for the precious proposal, but I reject this proposal from the following points. 1. This proposal becomes the change to Kernel, and adding the general name of "iterate" there has great influence. I think that it is neccessary to make it the method of Array at least. 2. A use-case is not known. Which becomes happy by it? There are similar methods already.(zip & transpose) Although the difference from "zip" is the number of times of repeating, which is the case needed frequently? If you can show that a suitable name as a method of Array and the use-case, please create a ticket newly. Regards, Masaya ---------------------------------------- Feature #4633: iterate method / extended version of for https://bugs.ruby-lang.org/issues/4633#change-27816 Author: rbjl (Jan Lelis) Status: Rejected Priority: Normal Assignee: tarui (Masaya Tarui) Category: Target version: =begin The Ruby world is known for using each, but it does not always look nice (although in most cases it does). I am proposing an iterate method that is nicely readable and allows easy iteration over multiple objects. It behaves like each for an single argument, but passes nils for Enumerables with multiple sizes: iterate [1,2], [3,4,5] do |e,f| puts "#{e},#{f}" end # outputs # 1,3 # 2,4 # ,5 A simple Ruby implementation: def iterate(*params) # params.shift.zip(*params).each{ |*elements| yield *elements } raise ArgumentError, "wrong number of arguments (0)" if params.empty? first = params.shift if params.empty? # single param - like each if block_given? first.map{|e| yield e } else first.map.to_enum end else # multiple params max_size = [first, *params].max_by(&:count).size padded_first = first.to_a + [nil]*(max_size - first.count) # append nils obj = padded_first.zip *params if block_given? obj.map{|es| yield *es } else obj.map.to_enum end end end A modified version of this request (no new method/statement) could be an alternative usage of for, something like: for e,f in [1,2], [3,4,5] puts "#{e},#{f}" end # outputs # 1,3 # 2,4 # ,5 This feature request does not add something needed, but I think, Ruby would look even more beautiful. =end -- http://bugs.ruby-lang.org/