Range

    • : Two dots denote an inclusive range, including x and y and all values in between (in mathematics: [x, y]) .
    • x...y: Three dots denote an exclusive range, including x and all values up to but not including y (in mathematics: [x, y)).

    Note

    An easy way to remember which one is inclusive and which one is exclusive it to think of the extra dot as if it pushes y further away, thus leaving it outside of the range.

    The begin and end values do not necessarily need to be of the same type: true..1 is a valid range, although pretty useless since Enumerable methods won’t work with incompatible types. They need at least to be comparable.

    1. numbers.select(6..) # => [10, 8]
    2. numbers.select(..6) # => [1, 3, 4, 5]
    3. numbers[2..] = [3, 4, 5, 8]
    4. numbers[..2] = [1, 10, 3]

    A range that is both begin-less and end-less is valid and can be expressed as .. or but it’s typically not very useful.