|
Ranges are series of numbers.
Here's how you can define a range:
myrange = 1..10
Myrange will now hold all numbers between 1 and 10 including.Myrange effectively turns into an array.
2nd way of defining a range:
myrange2 = 1...10
Myrange2 will hold all numbers between 1 and 10 except the last number : 10.
As I did with the previously discussed arrays and hashes, here are a few useful methods you can use on ranges.
How to find out the lowest number in a certain range:
puts myrange.min
How to find out the highest number in a certain range:
puts myrange.max
How to check if a number is part of a certain range:
myrange.include? (11)
Displaying a range's contents:
puts myrange.to_a
|