0
我正在嘗試創建紙牌遊戲的基礎知識。在創建/測試我的初始套件時,當我運行我的Ruby代碼時,我不斷收到以下錯誤消息。Ruby語法錯誤,意外的輸入結束,期待keyword_end
gofish.rb:30: syntax error, unexpected '\n', expecting :: or '[' or '.'
gofish.rb:73: syntax error, unexpected end-of-input, expecting keyword_end
deck.add_cards
我擡頭可能的解決方案,似乎我無法找到我的思念年底。它可能是別的嗎?我對ruby很陌生。
class Deck
def initialize
@ranks = %w(2 3 4 5 6 7 8 9 10 Jack Queen King Ace)
@suits = %w(Clubs Spades Hearts Diamonds)
@cards = []
@ranks.each do |rank|
@suits.each do |suit|
@cards << Card.new(rank, suit)
end
end
end
def shuffle
@cards.shuffle
end
def deal
@cards.shift
end
def empty?
@cards.empty?
end
def add_cards(*cards)
*cards.each do |card|
@cards << card
end #line 30
end
def to_s
output = ""
@cards.each do |card|
output = output + card.to_s + "\n"
end
return output
end
end
class Hand
def initialize
end
def search()
end
end
class Card
attr_reader :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def to_s
"#{@rank} of #{@suit}"
end
end
deck = Deck.new
puts deck.to_s
deck.shuffle
puts deck.to_s
deck.deal
deck.add_cards #line 73
您希望_us數行數多達30 73_? – mudasobwa
'* cards.each do | card |''⇒'cards.each do | card |' – mudasobwa
@mudasobwa編輯包含關鍵線號碼。感謝您的解決方案! –