From: Gavin Sinclair Date: 2002-09-24T16:22:25+09:00 Subject: Re: Picking arbitrary elements from an array ----- Original Message ----- From: > > > > How does this relate to Enumerable#select, > > which Array mixes in? Do we somehow get > > the functionality of both? > > Judging from some 1.7.3 experimenting, it seems that Array#select, if > given an argument, acts like #indices, and if given a block but no > argument, acts like #find_all (for which it used to be a synonym). If > given both, it raises an exception. > > I don't know if this is still under discussion, but in case it is... > This new flavor of #select doesn't feel to me like it has the right > name. Maybe I'm just used to the idea of select as involving a test, > rather than an index -- and in fact it still does, some of the time. > It's really the same name for two very different things. > > My instincts, such as they are, would lead me to lean toward a > multi-arg version of #at: > > [1,2,3].at(1,2) => [2,3] > > Or is there (not for the first time) a subtlety or two I'm not > getting? > > > David > [1,3,6].at(1,2) => [3,6] PROPOSED [1,3,6].at(1) => 3 ACTUAL [1,3,6].at(1) => [3] CONSISTENT WITH PROPOSAL #indices always returns an array, and has a really nice name, to boot. I'm sorry to see it go. BTW it's very important to consistently return an array, in case you call it in the following manner: indices = some_array values = arr.indices(*indices) The subsequent code expects "values" to be an array, even if "indices" contains zero or one elements. I agree that overloading "select" for two different purposes is a bad idea. Gavin