From: Rob Biedenharn Date: 2009-08-06T00:35:41+09:00 Subject: Re: Bizarre Range behavior On Aug 5, 2009, at 12:55 AM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Bizarre Range behavior" > on Wed, 5 Aug 2009 05:32:37 +0900, Rob Biedenharn > writes: > > |Knowing this, here's an even more bizzare-looking example: > | > |irb> "19".succ > |=> "20" > |irb> ("2".."19").to_a > |=> [] > |irb> ("2"..."20").to_a > |=> ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", > |"14", "15", "16", "17", "18", "19"] > > What if I sprinkle more magic to the language and change String#upto > to generate numerical sequences when all characters in edges are > digits, so that > > irb> ("2".."19").to_a > => ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", > "14", "15", "16", "17", "18", "19"] > irb> ("2"..."20").to_a > => ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", > "14", "15", "16", "17", "18", "19", "20"] > > Any opinion? I already made a patch for trunk. > > matz. I'd actually prefer *less* magic here. (And I hope that your second example with "2"..."20" wouldn't include "20" since the range excludes its end.) The surprising aspect is that the Range#to_a can give an array that has just the #begin. String#upto perhaps needs more magic to know that #succ will eventually work ("9".upto("10") as well as "cat".upto("bird")) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com