From: Peter Hickman Date: 2012-12-28T03:56:20+09:00 Subject: Re: numeric? --e89a8f923f5022a2a304d1da1a77 Content-Type: text/plain; charset=ISO-8859-1 On 27 December 2012 18:50, Jonan Scheffler wrote: > You might be better off to ask yourself why you need the type checking > anyway. If you have a method designed to handle an argument that might be a > string or an integer you might be trying to do two different things. > > If you're sure you want the integer you could just to_i the input. > > 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. --e89a8f923f5022a2a304d1da1a77 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 27 December 2012 18:50, Jonan Scheffler <jonans= cheffler@gmail.com> wrote:

You might be better off to ask yourself why= you need the type checking anyway. If you have a method designed to handle= an argument that might be a string or an integer you might be trying to do= two different things.

If you're sure you want the integer you could just to_i = the input.



Problem all strings will convert to integers.
=
"fred".to_i =3D> 0
"69skiddoo&qu= ot;.to_i =3D> 69
"".to_i =3D> 0

I suspect that these would not be considered numbers.

=
--e89a8f923f5022a2a304d1da1a77--