Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > numeric boolean check

Reply
Thread Tools

numeric boolean check

 
 
Jason Lillywhite
Guest
Posts: n/a
 
      03-17-2009
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-forum.com/.

 
Reply With Quote
 
 
 
 
Saji N. Hameed
Guest
Posts: n/a
 
      03-17-2009


> 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 http://www.velocityreviews.com/forums/(E-Mail Removed)
KOREA



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtle difference between boolean value and boolean comparison? Metre Meter Javascript 7 08-06-2010 08:40 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
Unable get Boolean and Numeric values from XLS into Dataset and Datagrid vighnesh ASP .Net 3 08-04-2005 02:16 PM
Unable get Boolean and Numeric values from XLS into Dataset and Datagrid vighnesh ASP .Net Datagrid Control 3 08-04-2005 02:16 PM
check if string contains numeric, and check string length of numeric value ief@specialfruit.be C++ 5 06-30-2005 01:08 PM



Advertisments