From: Wilson Bilkovich Date: 2006-11-18T14:20:51+09:00 Subject: Re: ruby equivalent PHP function is_numeric? On 11/17/06, David Vallner wrote: > ara.t.howard@noaa.gov wrote: > > On Sat, 18 Nov 2006, Josselin wrote: > > > >> After reading completely my Ruby book, I cannot find a function > >> equivalent to the PHP is_numeric? to test a String > >> > >> myString.is_numeric? (check only digits and dot character) => > >> return true or false > >> > >> does it exist ? or it's more complicated than that ? (need to build a > >> regex... ?) > >> > >> thanks > >> > >> joss > > > > > > > > harp:~ > cat a.rb > > def is_numeric?(n) Float n rescue false end > > > > def is_numeric?(n) begin Float n; return true rescue false end > > Predicate methods not returning a boolean make my skin crawl even if > it's all the same difference for conditionals. > Or the golf version: def is_numeric?(n) !!Float(n) rescue false end