All but last element of Ruby array

Viewed 111806

Let's say I have a Ruby array

a = [1, 2, 3, 4]

If I want all but the first item, I can write a.drop(1), which is great. If I want all but the last item, though, I can only think of this way

a[0..-2]   # or
a[0...-1]

but neither of these seem as clean as using drop. Any other built-in ways I'm missing?

14 Answers
Related