Another way to do it using Kernels built in validator, just as an idea.
However, I think code that build its functionality on exceptions should be avoided, and the other solutions are probably preferred.
def determine_type x
[:Integer, :Float, :Rational].each do |c|
return c if send(c, x) rescue ArgumentError
end
return :String
end
p determine_type(1) #=> :Integer
p determine_type('1') #=> :Integer
p determine_type('1.0') #=> :Float
p determine_type('1/1') #=> :Rational
p determine_type('ccc') #=> :String