On Aug 4, 2009, at 3:15 PM, Matthew K. Williams wrote: > On Wed, 5 Aug 2009, Scott Briggs wrote: > Can someone please explain this behavior in ruby (1.8.6p111): >> >>>> ("2"..."8").to_a >> => ["2", "3", "4", "5", "6", "7"] >>>> ("2".."8").to_a >> => ["2", "3", "4", "5", "6", "7", "8"] >>>> ("2".."9").to_a >> => ["2", "3", "4", "5", "6", "7", "8", "9"] >>>> ("2".."10").to_a >> => [] >>>> ("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 Well, it certainly isn't invalid. You can easily have a Range where the end is less than the begin value. r = 3..-1 => 3..-1 irb> r.to_a => [] irb> "hello"[r] => "lo" -Rob Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com