我正在尝试为一副纸牌创建散列,但我无法确定何时工作以使其成为王牌。我的所有密钥都没有显示为 A,仍在使用 JQK。显然我不明白红宝石中的开关是如何工作的。
def generateDeck
d1 = Hash.new
['C', 'D', 'H', 'S'].each do |suite|
case suite
when 'D'
loopStart = 14
loopEnd = 26
when 'H'
loopStart = 27
loopEnd = 39
when 'S'
loopStart = 40
loopEnd = 52
else
loopStart = 1
loopEnd = 13
end # of switch
loopStart.upto(loopEnd) do |loop|
puts("CurrentLoop: #{loop}")
puts("Should Be Ace: #{loop % 13 == 1}")
case loop
when (loop % 13 == 1)
d1['A' + suite] = loop
when 11
d1['J' + suite] = loop
when 12
d1['Q' + suite] = loop
when 13
d1['K' + suite] = loop
else
d1["#{loop}#{suite}"] = loop
end # of switch
end # of do
end # of do
d1['JA'] = 53
d1['JB'] = 54
return d1
end # of generateDecks
d1 = generateDeck