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)
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
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
=> false3.is_a? Numeric
=> true
Hope that helps.
James Edward G. II
On Apr 27, 2006, at 5:58 PM, Daniel H. wrote:
1.is_a?(Numeric) # => true
Or Numeric === 1
On 4/27/06, Todd S. [email protected] wrote:
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.
Don’t forget the question mark.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs