Leem.fin Leem.fin - 1 year ago 61
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 Source

There are several ways:

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