valid string is integer ruby code example
Example 1: ruby is int
1.is_a? Integer
=> true
"[email protected]".is_a? Integer
=> false
nil.is_a? Integer
=> false
Example 2: ruby check if string is integer
class String
def numeric?
Float(self) != nil rescue false
end
end
"Hello World!".numeric?