From: Dave Thomas Date: 2001-04-28T03:55:45+09:00 Subject: [ruby-talk:14344] Re: array as index to array jonas writes: > If a is an array, a[n] returns the n:th element. a[n..m] returns the > n:th to the m:th element. If b is an array b=[x,y,z], it would be no > surprise if a[b] returned the x:th, y:th and z:th element of a instead > of: > > a=(42..97).to_a > b=[3,7,9] > a[b] > TypeError: failed to convert Array into Integer > (irb):17:in `[]' > (irb):17:in `irb_binding' > > Or, what is the ruby way of doing this? Somewhat indirectly, you can use indexes (or indices) a = (42..97).to_a b = [3, 7, 9] a.indexes(*b) #=> [45, 49, 51] However, your initial suggestion might be interesting to consider as an RCR. Dave