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
# File 'lib/fiftytwo/has_cards.rb', line 23

def locate(identifier)
  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



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

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