a = [1,2,3,4,5,6,7,8,9] a.values_at(*(1...7).step(2)) - [nil]
Although the - [nil] part - [nil] not needed in the above case, it serves just in case your range exceeds the size of the array, otherwise you might get something like this:
a = [1,2,3,4,5,6,7,8,9] a.values_at(*(1..23).step(2))
source share