Class: Deck

Inherits:
Object
  • Object
show all
Defined in:
lib/deck.rb

Overview

The 40-card deck used in this game

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeck

Returns a new instance of Deck.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/deck.rb', line 4

def initialize
  @cards = Array.new
  for suit in CardDeck::Card::SUIT
    stock "Ace", suit
    stock "King", suit
    stock "Queen", suit
    stock "Jack", suit
    for num in (2..7).to_a; stock num, suit; end
  end
  @cards.shuffle!
end

Instance Attribute Details

#cardsObject (readonly)

The cards in the deck



3
4
5
# File 'lib/deck.rb', line 3

def cards
  @cards
end

Instance Method Details

#drawObject

Draw a card from @cards



16
# File 'lib/deck.rb', line 16

def draw; @cards.shift; end

#lengthObject

How many cards are in @cards



15
# File 'lib/deck.rb', line 15

def length; @cards.length; end