Arrays commonly need to exclude the last value of an array, for example getting count of an array, and Ruby’s range class provides a quick syntax for this.

>> (1..10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 
>> (1...10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
 
# great for loops
>> (1...10).count 
=> 9

To remove the first integer try this.

>> [(1..10).to_a[1]..(1..10).count]
=> [2..10]

:)

Leave a Reply

Your email address will not be published. Required fields are marked *