私はTeam
クラスを持っています:
class Team
attr_accessor :teamplayers
def initialize
@team_players = []
end
def <<(player)
@team_players << player
end
def to_s
puts "THIS IS THE TEAM #{@team_players}"
end
end
でチームにメンバーを追加したい<<
。私はこのコードを使用します:
team << @goalkeepers.last
team << @defenders[-1..-4]
team << @midfielders[-1]
team << @attackers[-1..-2]
最初の行は正常に機能し、チームに1人のメンバーを追加します。ただし、他の行は、実際のメンバーではなく、私のチームに配列を追加します。
では、どうすればメンバーを個別に追加できますか?