From: Brandon Weaver Date: 2012-12-28T13:33:43+09:00 Subject: Re: numeric? --90e6ba211fbf0170f604d1e21043 Content-Type: text/plain; charset=ISO-8859-1 I've seen a similar solution as well. I've just monkey patched string with the float conversion. On Thu, Dec 27, 2012 at 10:22 PM, Grant Schoep wrote: > > Problem all strings will convert to integers. > > > > "fred".to_i => 0 > > "69skiddoo".to_i => 69 > > "".to_i => 0 > > > > I suspect that these would not be considered numbers. > > > In these cases, I just double convert i.e. > > irb(main):016:0> buffer = 'fred' > => "fred" > irb(main):017:0> buffer.to_i.to_s == buffer > => false > > And then > irb(main):001:0> buffer = '42' > => "42" > irb(main):002:0> buffer.to_i.to_s == buffer > => true > > -- > Posted via http://www.ruby-forum.com/. > > --90e6ba211fbf0170f604d1e21043 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I've seen a similar solution as well. I've just monkey patched stri= ng with the float conversion.

On Thu, Dec= 27, 2012 at 10:22 PM, Grant Schoep <lists@ruby-forum.com> wrote:
> Problem all strings w= ill convert to integers.
>
> "fred".to_i =3D> 0
> "69skiddoo".to_i =3D> 69
> "".to_i =3D> 0
>
> I suspect that these would not be considered numbers.


In these cases, I just double convert i.e.

irb(main):016:0> buffer =3D 'fred'
=3D> "fred"
irb(main):017:0> buffer.to_i.to_s =3D=3D buffer
=3D> false

And then
irb(main):001:0> buffer =3D '42'
=3D> "42"
irb(main):002:0> buffer.to_i.to_s =3D=3D buffer
=3D> true

--90e6ba211fbf0170f604d1e21043--