On 11/17/06, David Vallner <david / vallner.net> 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