Class: Deck
- Inherits:
-
Object
- Object
- Deck
- Defined in:
- lib/deck.rb
Overview
The 40-card deck used in this game
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
The cards in the deck.
Instance Method Summary collapse
-
#draw ⇒ Object
Draw a card from @cards.
-
#initialize ⇒ Deck
constructor
A new instance of Deck.
-
#length ⇒ Object
How many cards are in @cards.
Constructor Details
#initialize ⇒ Deck
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
#cards ⇒ Object (readonly)
The cards in the deck
3 4 5 |
# File 'lib/deck.rb', line 3 def cards @cards end |
Instance Method Details
#draw ⇒ Object
Draw a card from @cards
16 |
# File 'lib/deck.rb', line 16 def draw; @cards.shift; end |
#length ⇒ Object
How many cards are in @cards
15 |
# File 'lib/deck.rb', line 15 def length; @cards.length; end |