Please can someone explain what a range object means 2..-1.
Ruby koans has the following meaning in about_arrays.rb:
def test_slicing_with_ranges
array = [:peanut, :butter, :and, :jelly]
assert_equal [:peanut, :butter, :and], array[0..2]
assert_equal [:peanut, :butter], array[0...2]
assert_equal [:and, :jelly], array[2..-1]
end
The following website (found in another answer) explains how to work with cutting ranges:
Gary Wright, fragments of strings / arrays
From this I understand why the split gives the answer, which he does. The thing I don't understand is WHAT, which the range object belongs to. For the normal range, I can do:
(1..3).each { |x| puts(x) }
which gives the following output when executed in irb:
1
2
3
=> 1..3e
However, (2..-1).each { |x| puts(x) }it gives:
=> 2..-1
So what does range mean (2..-1)?
source
share