Class: DeckOfCards

Inherits:
Object
  • Object
show all
Defined in:
lib/deck-of-cards.rb,
lib/deck-of-cards/version.rb

Constant Summary collapse

SUITS =
%w[Hearts Spades Diamonds Clubs]
RANKS =
[*2..10, 'Jack', 'Queen', 'King', 'Ace']
VERSION =
'0.0.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeckOfCards

Returns a new instance of DeckOfCards.



12
13
14
15
# File 'lib/deck-of-cards.rb', line 12

def initialize
  @cards = []
  SUITS.product(RANKS) { |suit, rank| @cards << Card.new(rank, suit) }
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



7
8
9
# File 'lib/deck-of-cards.rb', line 7

def cards
  @cards
end

Instance Method Details

#cutObject Also known as: split



25
26
27
# File 'lib/deck-of-cards.rb', line 25

def cut
  @cards.rotate! @cards.count / 2
end

#drawObject



31
32
33
# File 'lib/deck-of-cards.rb', line 31

def draw
  @cards.shift
end

#shuffleObject



21
22
23
# File 'lib/deck-of-cards.rb', line 21

def shuffle
  @cards.shuffle!
end

#to_sObject



17
18
19
# File 'lib/deck-of-cards.rb', line 17

def to_s
  "#{@cards.count}-card deck."
end