Class: Holdem::Deck

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shuffle_cards = true) ⇒ Deck

Returns a new instance of Deck.



11
12
13
14
15
16
17
18
19
20
# File 'lib/deck.rb', line 11

def initialize(shuffle_cards=true)
  @cards = []
  Card::SUITS.each_byte do |suit|
    Card::RANKS.each_byte do |rank|
      @cards << Card.new(rank.chr + suit.chr)
    end
  end

  shuffle if shuffle_cards
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



5
6
7
# File 'lib/deck.rb', line 5

def cards
  @cards
end

Instance Method Details

#dealObject



22
23
24
# File 'lib/deck.rb', line 22

def deal
  @cards.pop
end

#remove(card) ⇒ Object



26
27
28
# File 'lib/deck.rb', line 26

def remove(card)
  @cards.delete_at(@cards.index(card))      
end

#shuffleObject



7
8
9
# File 'lib/deck.rb', line 7

def shuffle
  @cards = @cards.sort_by { rand }
end