Over a million developers have joined DZone.

Determine If A Syntactically Correct Series Of Characters Is Numeric (the Golf Version) In Ruby

·
Ruby Forum
http://www.ruby-forum.com/topic/88507#169102
 
Re: ruby equivalent PHP function is_numeric?
Posted by Wilson Bilkovich (Guest) on 18.11.2006 06:22  
On 11/17/06, David Vallner  wrote:
> >> regex... ?)
>
> 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


[or
def is_numeric?(n) !!Float(n) rescue false end
or
def is_numeric?(n) {!!Float(n) rescue false}
?]
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}