data = gets.chomp
data.is_a?(Integer)判断是否为整数Integer类型
data.is_a?(Float)浮点数类型
data.is_a?(Numeric)是否数字的判断
for instance:
require 'prime'
def first_n_primes(n)
# Check for correct input!
"n must be an integer" unless n.is_a? Integer
"n must be greater than 0" if n <= 0
# The Ruby 1.9 Prime class makes the array automatically!
prime = Prime.instance
prime.first n
end
first_n_primes(10)