From: Robert Klemme Date: 2007-11-23T07:15:01+09:00 Subject: Re: Checking whether a string is a number in disguise? On 22.11.2007 20:11, Peter Bunyan wrote: > OK, this seems to work: > > class String > def is_number? > Float(self) == self.to_f > rescue false > end > end That's an error prone approach because it relies on comparing floats (which is also superfluous here because the real work is done by Float and rescue). Why don't you just do def float? Float(self) rescue nil end Cheers robert