Is there a function in core ruby to determin if a variable is a number
or not?
something like @XX.is_numeric? or is_number(@XX)
···
--
Posted via http://www.ruby-forum.com/.
Is there a function in core ruby to determin if a variable is a number
or not?
something like @XX.is_numeric? or is_number(@XX)
--
Posted via http://www.ruby-forum.com/.
1.is_a?(Numeric) # => true
-- Daniel
On Apr 27, 2006, at 11:56 PM, Todd S. wrote:
Is there a function in core ruby to determin if a variable is a number
or not?something like @XX.is_numeric? or is_number(@XX)
Is there a function in core ruby to determin if a variable is a number
or not?something like @XX.is_numeric? or is_number(@XX)
>> "hello".is_a? Numeric
=> false
>> 3.is_a? Numeric
=> true
Hope that helps.
James Edward Gray II
On Apr 27, 2006, at 4:56 PM, Todd S. wrote:
Or Numeric === 1
On Apr 27, 2006, at 5:58 PM, Daniel Harple wrote:
1.is_a?(Numeric) # => true
Daniel Harple wrote:
1.is_a?(Numeric) # => true
-- Daniel
Thank you. I thought it was something to that effect.
Unfortunately it doesn't seem to work for me.
However I find that the above returns:
1.is_a(Numeric)
NoMethodError: undefined method `is_a' for 1:Fixnum
from (irb):4
while, 1.is_a? Numeric does indeed return true.
Don't forget the question mark.
On 4/27/06, Todd S. <tgate@mypublic.net> wrote:
Daniel Harple wrote:
> 1.is_a?(Numeric) # => true
>
> -- DanielThank you. I thought it was something to that effect.
Unfortunately it doesn't seem to work for me.However I find that the above returns:
1.is_a(Numeric)
NoMethodError: undefined method `is_a' for 1:Fixnum
from (irb):4
from :0while, 1.is_a? Numeric does indeed return true.