FANDOM


Range Edit

A Range represents an interval—a set of values with a beginning and an end.

Example Ranges Edit

 ('a'..'e').to_a    #=> ["a", "b", "c", "d", "e"]
 (1..5).to_a        #=> [1, 2, 3, 4, 5]
 (-5..-1).to_a      #=> [-5, -4, -3, -2, -1]
 (-1..-5).to_a      #=> []

Another thing to note is that you can use ... to use a range from the start but not including the end ie.

 ('a'...'d').to_a   #=> ["a", "b", "c"]


External Link Edit

Ruby Docs: Range