In Ruby 1.8.7 and prior, Enumerable::each_with_index did not accept any arguments. In Ruby 1.9, it will accept an arbitrary number of arguments. Documentation/code shows that it simply passes those arguments along to ::each. With the built in and standard library Enumerables, I believe passing an argument will yield an error, since the Enumerable's ::each method isn't expecting parameters.

So I would guess this is only useful in creating your own Enumerable in which you do create an ::each method that accepts arguments. What is an example where this would be useful?

Are there any other non-obvious consequences of this change?

1

There are 1 best solutions below

3
On

I went through some gems code and found almost no uses of that feature. One that it does, spreadsheet:

def each skip=dimensions[0], &block
  skip.upto(dimensions[1] - 1) do |idx|
    block.call row(idx)
  end
end

I don't really see that as an important change: #each is the base method for classes that mix-in module Enumerable, and methods added (map, select, ...) do not accept arguments.