Module: FiftyTwo::HasCards

Extended by:
Enumerable
Included in:
Deck, Hand
Defined in:
lib/fiftytwo/has_cards.rb

Constant Summary collapse

CardUnavailableError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



6
7
8
# File 'lib/fiftytwo/has_cards.rb', line 6

def cards
  @cards
end

Instance Method Details

#drawObject



15
16
17
# File 'lib/fiftytwo/has_cards.rb', line 15

def draw
  cards.shift
end

#initialize(cards = []) ⇒ Object



11
12
13
# File 'lib/fiftytwo/has_cards.rb', line 11

def initialize(cards = [])
  @cards = cards
end

#locate(identifier) ⇒ Object



23
24
25
26
# File 'lib/fiftytwo/has_cards.rb', line 23

def locate(identifier)
  return cards[identifier] if identifier.is_a?(Integer)
  cards.find { |c| c.identifier == identifier.upcase }
end

#renderObject



19
20
21
# File 'lib/fiftytwo/has_cards.rb', line 19

def render
  map(&:render).join(" ")
end

#transfer(cards, destination = nil) ⇒ Object



28
29
30
# File 'lib/fiftytwo/has_cards.rb', line 28

def transfer(cards, destination = nil)
  gather(cards).map { |c| (destination || c.deck) << self.cards.delete(c) }
end