From: Jason Nordwick Date: 2006-09-16T00:15:05+09:00 Subject: Re: arbitrary indexes given that Array[int,int] is already taken syntax, Array[Array] is perfectly acceptable syntax for arbitrary list indexing, even if the immediate form might look a little ugly: a[[1,3,4,5,7]]. -j MonkeeSage wrote: > Farrel Lifson wrote: >> Be careful though as you've broken some functionality as Array#[] can >> take two arguments to return the y elements starting at index x. >> [1,2,3,4,5,6,7][2,3] = [3,4,5] >> Your modification would make >> [1,2,3,4,5,6,7][2,3] = [3,4] > > Yup, caveat emptor. Jason indicated that he was aware of the default > functionality though, so I assume he would be mindful of that gotcha. > > Also, I see that my code above wouldn't work for one of his desired > uses: > > a=[0,11,22,33,44,55] > b=[1,3] > a[b] # => [11, 33] > > For that to be supported as well, the implementation would have to be > something like: > > class Array > def [](*args) > if args.size == 1 > if args.at(0).instance_of?(Array) > values_at(*args.at(0)) > else > at(*args) > end > else > values_at(*args) > end > end > end > > Regards, > Jordan > >