From: C Erler Date: 2006-05-13T00:13:27+09:00 Subject: Re: Is there a method for incrementing string names?!? ------=_Part_29951_1056603.1147446804604 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Here's a method to do it : def inc name parts =3D name.scan(/^(.*\D)(\d+)$/).first if parts.nil? "#{name}1" else "#{parts.first}#{parts.last.to_i + 1}" end end On 12/05/06, Human Dunnil wrote: > > Hello, > I have model which has a property named "name", I want to append a > number to the end of the name when there is similar name in db. > > name, name1, name2... > > Is there a ready to use method in ruby and/or rails for doing so? > > Thanks in advance, > - Dunnil > > ------=_Part_29951_1056603.1147446804604--