```On Wed, 5 Aug 2009, Scott Briggs wrote:

> Matt, that doesn't explain why "1".."11" works and "2".."11" doesn't
> work.

irb(main):015:0> "1" < "11"
=> true
irb(main):016:0> "2" < "11"
=> false

irb(main):021:0> "11" < "2"
=> true

This is true because it's comparing strings to get the range -- it
compares the first character of each string, then stops when it can't go
any further.

Try this for an example of how the expansion is occurring:

("a".."cat".to_a

(I'm only putting a portion of it here)

=> ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "aa", "ab",
....
"caa", "cab", "cac", "cad", "cae", "caf", "cag", "cah", "cai", "caj",
"cak", "cal", "cam", "can", "cao", "cap", "caq", "car", "cas", "cat"]

In string order, it's going to compare strings of length 1 first, then
strings of length 2, etc...  Here's another example (with an attempt at an
explanation):

irb(main):019:0> ("11" .. "2").to_a
=> ["11"]

As we've seen before, "11" < "2", so it's a part of the range, but then it
stops, we're done.

Matt

>
> Scott
>
> Matthew K. Williams wrote:
>> On Wed, 5 Aug 2009, Scott Briggs wrote:
>>
>>>>> ("2".."11").to_a
>>> => []
>>>>> ("1".."11").to_a
>>> => ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
>>>
>>
>> It's because you're using strings -- "11" comes before "2", hence the
>> failure, because it's an invalid range, just as if you had (11 .. 2) is
>> invalid.
>>
>> Matt
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

```