Is_number function?


#1

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)


#2

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)

1.is_a?(Numeric) # => true

– Daniel


#3

On Apr 27, 2006, at 4: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)

“hello”.is_a? Numeric
=> false

3.is_a? Numeric
=> true

Hope that helps.

James Edward G. II


#4

On Apr 27, 2006, at 5:58 PM, Daniel H. wrote:

1.is_a?(Numeric) # => true

Or Numeric === 1


#5

On 4/27/06, Todd S. removed_email_address@domain.invalid wrote:

However I find that the above returns:

1.is_a(Numeric)
NoMethodError: undefined method `is_a’ for 1:Fixnum
from (irb):4
from :0

while, 1.is_a? Numeric does indeed return true.

Don’t forget the question mark.


#6

Daniel H. 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
from :0

while, 1.is_a? Numeric does indeed return true.