Class: HDeck::Deck
Overview
Provides a Harrow deck for a Card Caster to interact with
Instance Method Summary collapse
- #draw(replace: true) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ Deck
constructor
A new instance of Deck.
- #length ⇒ Object
- #shuffle ⇒ Object
Constructor Details
#initialize ⇒ Deck
Returns a new instance of Deck.
6 7 8 9 |
# File 'lib/hdeck/deck.rb', line 6 def initialize card_data = JSON.parse(File.read('cards.json')) @cards = get_cards(card_data) end |
Instance Method Details
#draw(replace: true) ⇒ Object
19 20 21 |
# File 'lib/hdeck/deck.rb', line 19 def draw(replace: true) replace ? @cards.last : @cards.pop end |
#each(&block) ⇒ Object
15 16 17 |
# File 'lib/hdeck/deck.rb', line 15 def each(&block) @cards.each(&block) end |
#length ⇒ Object
11 12 13 |
# File 'lib/hdeck/deck.rb', line 11 def length @cards.length end |
#shuffle ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hdeck/deck.rb', line 23 def shuffle counter = @cards.length - 1 while counter > 0 ri = rand(counter) @cards[counter], @cards[ri] = @cards[ri], @cards[counter] counter -= 1 end @cards end |