From: Robert Klemme Date: 2012-07-13T18:08:23+09:00 Subject: Re: how to check string is numeric or not On Fri, Jul 13, 2012 at 10:19 AM, Lars Haugseth wrote: > If o is allowed to be a Fixnum, you need to cast to string first: > > /\A\d+\z/ === o.to_s WTF? (That's the first time I remember me writing this here.) Let me get that straight: you want to convert something which you *know* is an integer to a String to check whether it is an integer? If o is allowed to be an integer type then you would better check that directly (e.g. with Integer === o). But it get's better: irb(main):010:0> a=[1,1<<50,"1"] => [1, 1125899906842624, "1"] irb(main):011:0> a.each {|x| y=Integer(x); printf "type %p converted %p type %p\n", x.class, y, y.class} type Fixnum converted 1 type Fixnum type Bignum converted 1125899906842624 type Bignum type String converted 1 type Fixnum => [1, 1125899906842624, "1"] Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/