From: Alex Coplan Date: 2012-08-06T08:28:22+09:00 Subject: Re: how perform addition a text value with an integer --Apple-Mail=_1A4E87FD-8F55-4796-AF73-313686FE09D0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Try this: irb(main):001:0> cuid =3D "1008" =3D> "1008" irb(main):002:0> cuid =3D "#{cuid.to_i + 1}" =3D> "1009" The problem is that when you call Integer(cuid) or cuid.to_i you don't = change the type of cuid, it only *returns* an integer. On 6 Aug 2012, at 00:16, Henry Maddocks wrote: >=20 > On 6/08/2012, at 11:01 AM, Fosiul Alam wrote: >>=20 >> i tryed couple of ways.. but no luck >>=20 >>=20 >> Integer(cuid) >> cuid =3D cuid +1 >> puts cuid >>=20 >> but it through the bellow error >>=20 >> `+': can't convert Fixnum into String (TypeError) >=20 >=20 >=20 > Here a 'correct' version of your script. >=20 > irb(main):001:0> cuid =3D "1008" > =3D> "1008" > irb(main):002:0> new_cuid =3D Integer cuid > =3D> 1008 > irb(main):003:0> new_cuid +=3D 1 > =3D> 1009 > irb(main):004:0> cuid =3D "#{new_cuid}" > =3D> "1009" > irb(main):005:0> puts cuid > 1009 > =3D> nil >=20 > or >=20 > irb(main):001:0> cuid =3D "1008" > =3D> "1008" > irb(main):002:0> puts "#{Integer(cuid) + 1}" > 1009 > =3D> nil >=20 >=20 > Henry >=20 --Apple-Mail=_1A4E87FD-8F55-4796-AF73-313686FE09D0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
=3D> "1008"
irb(main):002:0> cuid =3D= "#{cuid.to_i + 1}"
=3D> = "1009"

The problem is that when you call = Integer(cuid) or cuid.to_i you don't change the type of cuid, it only = *returns* an integer.

On 6 Aug 2012, at 00:16, Henry = Maddocks wrote:


On = 6/08/2012, at 11:01 AM, Fosiul Alam wrote:

i tryed = couple of ways.. but no luck


Integer(cuid)
cuid =3D cuid = +1
puts cuid

but it through the bellow error

`+': can't = convert Fixnum into String = (TypeError)



<= /div>
Here a 'correct' version of your = script.

irb(main):001:0> cuid =3D = "1008"
=3D> "1008"
irb(main):002:0> new_cuid =3D= Integer cuid
=3D> 1008
irb(main):003:0> = new_cuid +=3D 1
=3D> 1009
irb(main):004:0> = cuid =3D "#{new_cuid}"
=3D> = "1009"
irb(main):005:0> puts = cuid
1009
=3D> = nil

or

irb(ma= in):001:0> cuid =3D "1008"
=3D> = "1008"
irb(main):002:0> puts "#{Integer(cuid) + = 1}"
1009
=3D> = nil


Henry


= --Apple-Mail=_1A4E87FD-8F55-4796-AF73-313686FE09D0--