Class: Rb21::Deck
- Inherits:
-
Object
- Object
- Rb21::Deck
- Defined in:
- lib/rb21/deck.rb
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #draw ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Deck
constructor
A new instance of Deck.
- #reshuffle ⇒ Object
Constructor Details
#initialize ⇒ Deck
Returns a new instance of Deck.
7 8 9 10 11 |
# File 'lib/rb21/deck.rb', line 7 def initialize @cards = [] @discarded = [] build end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
5 6 7 |
# File 'lib/rb21/deck.rb', line 5 def cards @cards end |
Instance Method Details
#draw ⇒ Object
13 14 15 16 |
# File 'lib/rb21/deck.rb', line 13 def draw raise "Draw pile is empty" if empty? (@discarded << @cards.shift).last end |
#empty? ⇒ Boolean
18 19 20 |
# File 'lib/rb21/deck.rb', line 18 def empty? @cards.size.zero? end |
#reshuffle ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rb21/deck.rb', line 22 def reshuffle raise "The deck is not empty" unless @cards.size.zero? @cards = @discarded @discarded = [] @cards.shuffle! end |