[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

numeric boolean check

Jason

3/17/2009 4:44:00 AM

Is there a way to check for numeric in Ruby similar to the way you can
in Lisp?

(number? 5) => #t
(number? -0.453) => #t
(number? 'a) => #f

returns true for any numeric value and false for everything else.

This:
Float(x) rescue false

almost works but doesn't return true on numeric values
--
Posted via http://www.ruby-....

1 Answer

Saji N. Hameed

3/17/2009 4:56:00 AM

0



> Is there a way to check for numeric in Ruby similar to the way you can
> in Lisp?
>
> (number? 5) => #t
> (number? -0.453) => #t
> (number? 'a) => #f

irb(main):021:0> (10/3.0).is_a? Numeric
=> true
irb(main):022:0> (10/3).is_a? Numeric
=> true
irb(main):023:0> "a".is_a? Numeric
=> false


saji
--
--
Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 saji@apcc21.net
KOREA