Leem.fin Leem.fin - 6 months ago 8
Ruby Question

How to check if a variable is a number or a string?

How to check if a variable is a number or a string in Ruby?

Answer

There are several ways:

>> 1.class #=> Fixnum
>> "foo".class #=> String
>> 1.is_a? Numeric #=> true
>> "foo".is_a? String #=> true
Comments