Ruby: is there a way to get the values from an array using an array of indexs all in one line?
array: [1,2,1,1,2,2,2,1,1,1,1,1]
index开发者_StackOverflow中文版es: [0,3,5,1]
output: [1,1,2,2]
output = array.values_at(*indexes)
Note that you have to splat the indexes argument, values_at accepts a list of integers or ranges as argument
精彩评论