Sha256: d6f760ed84f05ef8f5d4258fe1f467d9b836b8e05cd5d4b4f42f3db515f33ab4
Contents?: true
Size: 802 Bytes
Versions: 9
Compression:
Stored size: 802 Bytes
Contents
# frozen_string_literal: true module Basketball module Org # Base class describing a team. A team here is bare metal and is just described by an ID # and a collection of Player objects. class Team < Entity attr_reader :players def initialize(id:, players: []) super(id) @players = [] players.each { |p| sign!(p) } freeze end def to_s ([super.to_s] + players.map(&:to_s)).join("\n") end def signed?(player) players.include?(player) end def sign!(player) raise ArgumentError, 'player is required' unless player raise PlayerAlreadySignedError, "#{player} already signed by #{self}" if signed?(player) players << player self end end end end
Version data entries
9 entries across 9 versions & 1 rubygems