Does Rails 3 or Ruby have a built-in way to check if a variable is an integer?
For example,
1.is_an_int #=> true \"dadadad@asdasd.net\".is_an_int
Probably you are looking for something like this:
Accept "2.0 or 2.0 as an INT but reject 2.1 and "2.1"
num = 2.0 if num.is_a? String num = Float(num) rescue false end new_num = Integer(num) rescue false puts num puts new_num puts num == new_num
num = 2.0
if num.is_a? String num = Float(num) rescue false end
new_num = Integer(num) rescue false
puts num
puts new_num
puts num == new_num