Next | 3.4 Ranges | Prev |
Ranges are natural, Sunday to Saturday, January to December, 0 to 9, a to f.
myRange = 100..999 0...myArray.length 'a'..'z'
p (-2 .. 2).to_a p ('Bow' ... 'Boz').to_a p %w(Sun Mon Tue Wed Thu Fri Sat)[3..5].join(', ') |
[-2, -1, 0, 1, 2] ["Bow", "Box", "Boy"] "Wed, Thu, Fri" |
Ranges may be used as intervals:
(2 .. 4).include?(3.1415926) ('perl' .. 'poni') === 'ruby' |
true false |
Next | Ruby for Perl programmers | Prev |