如果用戶鍵入什麼比其他一些,此外在1之間的數字任意數量的 - 32,我需要它要求再次輸入。檢查用戶輸入的是在一定範圍內的紅寶石
它給我一個錯誤,當我在1..32
def cut_the_deck
puts "You get to cut the deck to make it even more random!"
puts "Type a number between 1 and 32. That's where the deck will be cut!"
cut_number = gets.chomp
cut_number = cut_number.to_i
if cut_number in 1..32
puts "Number in range"
else
puts "Number NOT in range"
cut_the_deck
end
end
鏈接[可比較](http://ruby-doc.org/core-2.0.0/Comparable.html#method-i-between-3F)rdoc。 – orde