use regular expression check whether a string is a number

        if num=~ /\d+/
          buy_num=num.to_i
        else
          buy_num=1
        end

1
down vote accept

You forgot to include the class you were testing against:

"1".is_a?(Integer) # false
1.is_a?(Integer) # true

你可能感兴趣的:(expression,regular)