Ruby Ranges
Ruby Ranges
The Ruby range represents an interval of values.
The syntax of Ruby range allow you to include or exclude its ending value.
Ranges syntax
(1..10) (1...10)
Ranges example
r1 = (1..5).to_a
r2 = (1...5).to_a
r3 = (1..5).to_a.reverse
puts "#{r1}"
puts "#{r2}"
puts "#{r3}"
Output
[1, 2, 3, 4, 5]
[1, 2, 3, 4]
[5, 4, 3, 2, 1]