Class: DeckOfCards
- Inherits:
-
Object
- Object
- DeckOfCards
- 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
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #cut ⇒ Object (also: #split)
- #draw ⇒ Object
-
#initialize ⇒ DeckOfCards
constructor
A new instance of DeckOfCards.
- #shuffle ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ DeckOfCards
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
#cards ⇒ Object (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
#cut ⇒ Object Also known as: split
25 26 27 |
# File 'lib/deck-of-cards.rb', line 25 def cut @cards.rotate! @cards.count / 2 end |
#draw ⇒ Object
31 32 33 |
# File 'lib/deck-of-cards.rb', line 31 def draw @cards.shift end |
#shuffle ⇒ Object
21 22 23 |
# File 'lib/deck-of-cards.rb', line 21 def shuffle @cards.shuffle! end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/deck-of-cards.rb', line 17 def to_s "#{@cards.count}-card deck." end |