可能是最糟糕的提问方式,但我是新手,正在尽力解释我的问题。
我正在实现一个 Ruby Blackjack 游戏。你可以在这里看到我所拥有的回购/来源:https ://bitbucket.org/subem81/blackjack
这是关注的特定部分(保留在“手”模块中,该模块包含在使用我认为是 mixin 的 Dealer 和 Player 类中):
def show_hand
if self.class.to_s == 'Dealer'
self.hand.each do |card|
card.show_card
end
elsif self.class.to_s == 'Player'
else
puts "A Random person is showing their hand."
end
end
它为每个 Card 对象调用 show_card() 方法。或者我是这么想的。我一直在卡片对象上没有方法错误。这是那个错误:
$ ruby blackjack.rb
Welcome to Mike's Blackjack.
blackjack.rb:35:in `block in show_hand': undefined method `show_card' for
[# <Card:0x007fe504110918 @suit="Spades", @card_type="King">]:Array (NoMethodError)
from blackjack.rb:34:in `each'
from blackjack.rb:34:in `show_hand'
from blackjack.rb:21:in `setup_players'
from blackjack.rb:6:in `initialize'
from blackjack.rb:116:in `new'
from blackjack.rb:116:in `<main>'