From: "David A. Black" Date: 2003-12-04T03:48:02+09:00 Subject: Re: strings and ranges Hi -- On Thu, 4 Dec 2003 charlie.mills@milliman.com wrote: > The following program doesn't execute as I would expect: > > #!/usr/bin/ruby > > stringy = "X" > > 1.upto(10) do |i| > puts stringy > stringy.succ! > end > > "X".upto("AG") do |ss| > puts ss > end > > puts "'AB' > 'AA' = #{'AB' > 'AA'}" > puts "'X' < 'AA' = #{'X' < 'AB'}" Interesting -- just like "9" and "10" (i.e., "9" > "9".succ). > # The code below gets around my problem... > > stringy = "X" > while true > puts stringy > stringy.succ! > break if stringy == "AH" > end > > # Is there a better way? How about this: x = "X" puts (0...10).map { x.succ! .dup } (You need the .dup or you'll end up with 10 of x, all the same string.) David -- David A. Black dblack@wobblini.net