0

我有一个代表一副纸牌的哈希值,我试图弄清楚如何从纸牌中删除一张特定的卡片。请让我知道我应该学习或阅读以提供帮助的任何建议或方法。

@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}
}
4

1 回答 1

4

这很简单

def delete a, b
  @deck_of_cards[a].delete(b)
end

delete :hearts, :three

@deck_of_cards # => {:hearts=>{:two=>2, :four=>4, :five=>5, :six=>6, ...
于 2012-11-19T03:28:30.353 回答