我正在尝试使用嵌套哈希。我有一副纸牌表示如下:
deck_of_cards = {
:hearts => {:two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :jack => 10,
:queen => 10, :king => 10, :ace => 11},
:spades => {:two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :jack => 10,
:queen => 10, :king => 10, :ace => 11},
:clubs => {:two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :jack => 10,
:queen => 10, :king => 10, :ace => 11},
:diamonds => {:two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :jack => 10,
:queen => 10, :king => 10, :ace => 11}
}
我的目标是能够从牌组中取出一张特定的牌,并在没有那张牌的情况下归还牌组。任何人都可以帮助我如何遍历哈希并删除像两个俱乐部这样的卡吗?
deck_of_cards[:two][:clubs]
此代码可用于删除一副牌,但我不知道如何删除特定牌
deck_of_cards.delete_if {|k, v| k == :spades}