I'm learning Ruby, and have just gotten into some stuff about arrays and ranges. I've run into something about slices that, while it makes sense at first glance, confuses me a bit when i look deeper into it.
irb says that (2..-1).to_a
is an empty array. Meaning no values in the range, right?
But if i use that same range in [:a, :b, :c, :d, :e][2..-1]
, i get back [:c, :d, :e]
rather than an empty array.
Now, i'm aware that -1 represents the last element of the array, so it kinda makes sense that what got picked, did. But if the range itself would be empty, how is it selecting anything?