From: ideal one Date: 2011-10-18T03:09:58+09:00 Subject: Re: Ruby functions to split numbers Josh Cheek wrote in post #1026729: > On Fri, Oct 14, 2011 at 4:54 PM, ideal one > wrote: > >> > keep in mind that a number with a leading zero makes ruby think the base >> Hello there, >> -- >> Posted via http://www.ruby-forum.com/. >> >> > Strings have implemented on them the method "next" which, for numerical > strings, seems to respect numerical iteration > > n = '0' > 15.times do > n = n.next # => "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", > "11", > "12", "13", "14", "15" > end > > > I'm not 100% sure that this is compatible across all versions of Ruby, > you > should definately have a test to make sure that it increments them as > you > expect. You should also consider what happens when you have something > like > "999", is it supposed to go to "1000", which would cause it to gain a > digit? > If not, you'll need to add special handling for that situation. hi there... n.next works perfectly for me, I am using ruby 1.8.7 version. i tried 999, 1239999 and also other variations i can think of, it works perfectly. Cheers -- Posted via http://www.ruby-forum.com/.