if num=~ /\d+/ buy_num=num.to_i else buy_num=1 end 1down voteaccept You forgot to include the class you were testing against: "1".is_a?(Integer) # false1.is_a?(Integer) # true