« Return to Thread: Proposal: Array#walker

Re: Proposal: Array#walker

by Wolfgang Nádasi-donner-2 :: Rate this Message:

Reply to Author | View in Thread

David A. Black schrieb:
> On Wed, 14 Nov 2007, Kornelius Kalnbach wrote:
>> I think this is a very specialized method that should not go into the
>> core library...
> I agree; it might be a technique you'd want to do sometimes, but I'd
> put it in the category of use cases that can be addressed with what's
> there already and don't need dedicated core methods of their own.

The only reason I put it here is, that I don't see a way to express it without
using the index positions on the basis of existing methods. Insofar it is an
elementary method of class Array. Some method that splits an Array and presents
the whole Array for each iteration is missing.m Maybe something like this proposal:

Trans schrieb:
 >   a.each_with_index do |el, i|
 >     pre, post = a[0,i], a[i+1..-1]
 >     ...
 >   end
 >
 > That's not too bad, so I'm not sure it's worth it (?)
 >
 > However, a few times I've wanted a nicer way to split the array at an
 > index. Something like:
 >
 >   a.each_with_index do |el, i|
 >     pre, post = *a.crack(i)
 >     ...
 >   end

Wolfgang Nádasi-Donner

 « Return to Thread: Proposal: Array#walker