Class: HDeck::Deck

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

Overview

Provides a Harrow deck for a Card Caster to interact with

Instance Method Summary collapse

Constructor Details

#initializeDeck

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

#lengthObject



11
12
13
# File 'lib/hdeck/deck.rb', line 11

def length
  @cards.length
end

#shuffleObject



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